converting a .mat file with table to a .mat file with cell array










0















I need to convert a .mat file that contains a variable 't' of the type table to a cell. This is because there is another code that reads a cell array and performs str2num and char functions on it. When the code uses the str2num and char functions on the table that needs conversion it throws an error " Error using char : Conversion to char from table is not possible ". Is there anyway I can convert the format of a .mat file(with a table) to the format of a different .mat file(containing cell arrays) so that the code written for the.mat files with cell arrays works for the .mat file with table?










share|improve this question

















  • 3





    Did you try reading in the file, converting the table to a cell, and writing to a new file?

    – Cris Luengo
    Nov 14 '18 at 7:38











  • Welcome to stackoverflow. This is not a coding service website. Show us, what you have done so far in a Minimal, Complete, and Verifiable example and you'll get help

    – gehbiszumeis
    Nov 14 '18 at 7:41















0















I need to convert a .mat file that contains a variable 't' of the type table to a cell. This is because there is another code that reads a cell array and performs str2num and char functions on it. When the code uses the str2num and char functions on the table that needs conversion it throws an error " Error using char : Conversion to char from table is not possible ". Is there anyway I can convert the format of a .mat file(with a table) to the format of a different .mat file(containing cell arrays) so that the code written for the.mat files with cell arrays works for the .mat file with table?










share|improve this question

















  • 3





    Did you try reading in the file, converting the table to a cell, and writing to a new file?

    – Cris Luengo
    Nov 14 '18 at 7:38











  • Welcome to stackoverflow. This is not a coding service website. Show us, what you have done so far in a Minimal, Complete, and Verifiable example and you'll get help

    – gehbiszumeis
    Nov 14 '18 at 7:41













0












0








0








I need to convert a .mat file that contains a variable 't' of the type table to a cell. This is because there is another code that reads a cell array and performs str2num and char functions on it. When the code uses the str2num and char functions on the table that needs conversion it throws an error " Error using char : Conversion to char from table is not possible ". Is there anyway I can convert the format of a .mat file(with a table) to the format of a different .mat file(containing cell arrays) so that the code written for the.mat files with cell arrays works for the .mat file with table?










share|improve this question














I need to convert a .mat file that contains a variable 't' of the type table to a cell. This is because there is another code that reads a cell array and performs str2num and char functions on it. When the code uses the str2num and char functions on the table that needs conversion it throws an error " Error using char : Conversion to char from table is not possible ". Is there anyway I can convert the format of a .mat file(with a table) to the format of a different .mat file(containing cell arrays) so that the code written for the.mat files with cell arrays works for the .mat file with table?







matlab






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 7:35









NSKNSK

1




1







  • 3





    Did you try reading in the file, converting the table to a cell, and writing to a new file?

    – Cris Luengo
    Nov 14 '18 at 7:38











  • Welcome to stackoverflow. This is not a coding service website. Show us, what you have done so far in a Minimal, Complete, and Verifiable example and you'll get help

    – gehbiszumeis
    Nov 14 '18 at 7:41












  • 3





    Did you try reading in the file, converting the table to a cell, and writing to a new file?

    – Cris Luengo
    Nov 14 '18 at 7:38











  • Welcome to stackoverflow. This is not a coding service website. Show us, what you have done so far in a Minimal, Complete, and Verifiable example and you'll get help

    – gehbiszumeis
    Nov 14 '18 at 7:41







3




3





Did you try reading in the file, converting the table to a cell, and writing to a new file?

– Cris Luengo
Nov 14 '18 at 7:38





Did you try reading in the file, converting the table to a cell, and writing to a new file?

– Cris Luengo
Nov 14 '18 at 7:38













Welcome to stackoverflow. This is not a coding service website. Show us, what you have done so far in a Minimal, Complete, and Verifiable example and you'll get help

– gehbiszumeis
Nov 14 '18 at 7:41





Welcome to stackoverflow. This is not a coding service website. Show us, what you have done so far in a Minimal, Complete, and Verifiable example and you'll get help

– gehbiszumeis
Nov 14 '18 at 7:41












1 Answer
1






active

oldest

votes


















1














I will try to answer this question.
First let us create a table with numbers as cellstrings and save this table as a .mat file.



TestNumbersAsString = '42', '500', '288'';
t = table(TestNumbersAsString);
save('myTable.mat', 't');


Let us clear our workspace and load the file. convert the table to a cell and save this cell as a .mat file. Load this file again.



clearvars t
load('myTable.mat');
tAsCell = table2cell(t);
save('myCell.mat', 'tAsCell');
clearvars tAsCell
load('myCell.mat');


Convert and print the first element in the cell.



display(str2num(tAsCell1))


We could have used also the table.



display(str2num(t1,11))


EDIT:
please share an example and explain what you really want. You have never mentioned the column labels or NaN values.



tAsCellWithLabel = [t.Properties.VariableNames; table2cell(t)];



And you can remove the NaN values or check for NaN values and never call the function "str2num", if the cell value is NaN.
Check the "isnan" function.
There are so many ways to solve it.
But I do not know whats your data and how you want to use the data.






share|improve this answer

























  • This works but the lables of the table(column names) are not getting copied into the cell from the table.

    – NSK
    Nov 14 '18 at 21:45











  • Also, display(str2num(tAsCell1)) is 0

    – NSK
    Nov 14 '18 at 21:48











  • My table has NaN and ' ' on the table elements.

    – NSK
    Nov 14 '18 at 21:49











  • I need to convert a table in matlab to cellstr. This table has NaN values. I tried to remove the NaN and I am unable to. When I do table2cell, it converts to a cell but not cellstr. iscellstr(t) returns 0. Also the converted cell has ' ' around the column names. I need to use this data on a different program that accepts cell type. When I use the .mat file that has a table, it throws an error saying conversion to char from table is not possible. the program also does not allow me to to perform str2num on the table. previous Cellstr type is working fine with the program.

    – NSK
    Nov 15 '18 at 18:43










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295149%2fconverting-a-mat-file-with-table-to-a-mat-file-with-cell-array%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I will try to answer this question.
First let us create a table with numbers as cellstrings and save this table as a .mat file.



TestNumbersAsString = '42', '500', '288'';
t = table(TestNumbersAsString);
save('myTable.mat', 't');


Let us clear our workspace and load the file. convert the table to a cell and save this cell as a .mat file. Load this file again.



clearvars t
load('myTable.mat');
tAsCell = table2cell(t);
save('myCell.mat', 'tAsCell');
clearvars tAsCell
load('myCell.mat');


Convert and print the first element in the cell.



display(str2num(tAsCell1))


We could have used also the table.



display(str2num(t1,11))


EDIT:
please share an example and explain what you really want. You have never mentioned the column labels or NaN values.



tAsCellWithLabel = [t.Properties.VariableNames; table2cell(t)];



And you can remove the NaN values or check for NaN values and never call the function "str2num", if the cell value is NaN.
Check the "isnan" function.
There are so many ways to solve it.
But I do not know whats your data and how you want to use the data.






share|improve this answer

























  • This works but the lables of the table(column names) are not getting copied into the cell from the table.

    – NSK
    Nov 14 '18 at 21:45











  • Also, display(str2num(tAsCell1)) is 0

    – NSK
    Nov 14 '18 at 21:48











  • My table has NaN and ' ' on the table elements.

    – NSK
    Nov 14 '18 at 21:49











  • I need to convert a table in matlab to cellstr. This table has NaN values. I tried to remove the NaN and I am unable to. When I do table2cell, it converts to a cell but not cellstr. iscellstr(t) returns 0. Also the converted cell has ' ' around the column names. I need to use this data on a different program that accepts cell type. When I use the .mat file that has a table, it throws an error saying conversion to char from table is not possible. the program also does not allow me to to perform str2num on the table. previous Cellstr type is working fine with the program.

    – NSK
    Nov 15 '18 at 18:43















1














I will try to answer this question.
First let us create a table with numbers as cellstrings and save this table as a .mat file.



TestNumbersAsString = '42', '500', '288'';
t = table(TestNumbersAsString);
save('myTable.mat', 't');


Let us clear our workspace and load the file. convert the table to a cell and save this cell as a .mat file. Load this file again.



clearvars t
load('myTable.mat');
tAsCell = table2cell(t);
save('myCell.mat', 'tAsCell');
clearvars tAsCell
load('myCell.mat');


Convert and print the first element in the cell.



display(str2num(tAsCell1))


We could have used also the table.



display(str2num(t1,11))


EDIT:
please share an example and explain what you really want. You have never mentioned the column labels or NaN values.



tAsCellWithLabel = [t.Properties.VariableNames; table2cell(t)];



And you can remove the NaN values or check for NaN values and never call the function "str2num", if the cell value is NaN.
Check the "isnan" function.
There are so many ways to solve it.
But I do not know whats your data and how you want to use the data.






share|improve this answer

























  • This works but the lables of the table(column names) are not getting copied into the cell from the table.

    – NSK
    Nov 14 '18 at 21:45











  • Also, display(str2num(tAsCell1)) is 0

    – NSK
    Nov 14 '18 at 21:48











  • My table has NaN and ' ' on the table elements.

    – NSK
    Nov 14 '18 at 21:49











  • I need to convert a table in matlab to cellstr. This table has NaN values. I tried to remove the NaN and I am unable to. When I do table2cell, it converts to a cell but not cellstr. iscellstr(t) returns 0. Also the converted cell has ' ' around the column names. I need to use this data on a different program that accepts cell type. When I use the .mat file that has a table, it throws an error saying conversion to char from table is not possible. the program also does not allow me to to perform str2num on the table. previous Cellstr type is working fine with the program.

    – NSK
    Nov 15 '18 at 18:43













1












1








1







I will try to answer this question.
First let us create a table with numbers as cellstrings and save this table as a .mat file.



TestNumbersAsString = '42', '500', '288'';
t = table(TestNumbersAsString);
save('myTable.mat', 't');


Let us clear our workspace and load the file. convert the table to a cell and save this cell as a .mat file. Load this file again.



clearvars t
load('myTable.mat');
tAsCell = table2cell(t);
save('myCell.mat', 'tAsCell');
clearvars tAsCell
load('myCell.mat');


Convert and print the first element in the cell.



display(str2num(tAsCell1))


We could have used also the table.



display(str2num(t1,11))


EDIT:
please share an example and explain what you really want. You have never mentioned the column labels or NaN values.



tAsCellWithLabel = [t.Properties.VariableNames; table2cell(t)];



And you can remove the NaN values or check for NaN values and never call the function "str2num", if the cell value is NaN.
Check the "isnan" function.
There are so many ways to solve it.
But I do not know whats your data and how you want to use the data.






share|improve this answer















I will try to answer this question.
First let us create a table with numbers as cellstrings and save this table as a .mat file.



TestNumbersAsString = '42', '500', '288'';
t = table(TestNumbersAsString);
save('myTable.mat', 't');


Let us clear our workspace and load the file. convert the table to a cell and save this cell as a .mat file. Load this file again.



clearvars t
load('myTable.mat');
tAsCell = table2cell(t);
save('myCell.mat', 'tAsCell');
clearvars tAsCell
load('myCell.mat');


Convert and print the first element in the cell.



display(str2num(tAsCell1))


We could have used also the table.



display(str2num(t1,11))


EDIT:
please share an example and explain what you really want. You have never mentioned the column labels or NaN values.



tAsCellWithLabel = [t.Properties.VariableNames; table2cell(t)];



And you can remove the NaN values or check for NaN values and never call the function "str2num", if the cell value is NaN.
Check the "isnan" function.
There are so many ways to solve it.
But I do not know whats your data and how you want to use the data.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 '18 at 9:41

























answered Nov 14 '18 at 10:56









atmb321atmb321

114




114












  • This works but the lables of the table(column names) are not getting copied into the cell from the table.

    – NSK
    Nov 14 '18 at 21:45











  • Also, display(str2num(tAsCell1)) is 0

    – NSK
    Nov 14 '18 at 21:48











  • My table has NaN and ' ' on the table elements.

    – NSK
    Nov 14 '18 at 21:49











  • I need to convert a table in matlab to cellstr. This table has NaN values. I tried to remove the NaN and I am unable to. When I do table2cell, it converts to a cell but not cellstr. iscellstr(t) returns 0. Also the converted cell has ' ' around the column names. I need to use this data on a different program that accepts cell type. When I use the .mat file that has a table, it throws an error saying conversion to char from table is not possible. the program also does not allow me to to perform str2num on the table. previous Cellstr type is working fine with the program.

    – NSK
    Nov 15 '18 at 18:43

















  • This works but the lables of the table(column names) are not getting copied into the cell from the table.

    – NSK
    Nov 14 '18 at 21:45











  • Also, display(str2num(tAsCell1)) is 0

    – NSK
    Nov 14 '18 at 21:48











  • My table has NaN and ' ' on the table elements.

    – NSK
    Nov 14 '18 at 21:49











  • I need to convert a table in matlab to cellstr. This table has NaN values. I tried to remove the NaN and I am unable to. When I do table2cell, it converts to a cell but not cellstr. iscellstr(t) returns 0. Also the converted cell has ' ' around the column names. I need to use this data on a different program that accepts cell type. When I use the .mat file that has a table, it throws an error saying conversion to char from table is not possible. the program also does not allow me to to perform str2num on the table. previous Cellstr type is working fine with the program.

    – NSK
    Nov 15 '18 at 18:43
















This works but the lables of the table(column names) are not getting copied into the cell from the table.

– NSK
Nov 14 '18 at 21:45





This works but the lables of the table(column names) are not getting copied into the cell from the table.

– NSK
Nov 14 '18 at 21:45













Also, display(str2num(tAsCell1)) is 0

– NSK
Nov 14 '18 at 21:48





Also, display(str2num(tAsCell1)) is 0

– NSK
Nov 14 '18 at 21:48













My table has NaN and ' ' on the table elements.

– NSK
Nov 14 '18 at 21:49





My table has NaN and ' ' on the table elements.

– NSK
Nov 14 '18 at 21:49













I need to convert a table in matlab to cellstr. This table has NaN values. I tried to remove the NaN and I am unable to. When I do table2cell, it converts to a cell but not cellstr. iscellstr(t) returns 0. Also the converted cell has ' ' around the column names. I need to use this data on a different program that accepts cell type. When I use the .mat file that has a table, it throws an error saying conversion to char from table is not possible. the program also does not allow me to to perform str2num on the table. previous Cellstr type is working fine with the program.

– NSK
Nov 15 '18 at 18:43





I need to convert a table in matlab to cellstr. This table has NaN values. I tried to remove the NaN and I am unable to. When I do table2cell, it converts to a cell but not cellstr. iscellstr(t) returns 0. Also the converted cell has ' ' around the column names. I need to use this data on a different program that accepts cell type. When I use the .mat file that has a table, it throws an error saying conversion to char from table is not possible. the program also does not allow me to to perform str2num on the table. previous Cellstr type is working fine with the program.

– NSK
Nov 15 '18 at 18:43



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295149%2fconverting-a-mat-file-with-table-to-a-mat-file-with-cell-array%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo