Problem with matrices. Double and cell

1 view (last 30 days)
Hello,
I have a problem with a matlab code. The problem is that I want to make o txt file with my results. I am using the command "writetable" nut there is a problem with matrixes. In the picture I show you the format of the matrices.cr.png
How can I convert cell to double In order to make this code?
P.S. I ve tried commands : cell2table,table2array, but it doesn't works...
Thank you
  3 Comments
Eva-Maria Weiss
Eva-Maria Weiss on 1 Aug 2019
For converting cell arras to double array, you could use cell2mat:
Luna
Luna on 1 Aug 2019
To answer this, we must see what is inside the cell array. Could you please share it?

Sign in to comment.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 2 Aug 2019
for ii = 1:numel(CT)
if ~iscell(CT{ii})
CT{ii} = num2cell(CT{ii});
end
end
T = cell2table(cat(2,CT{:}));
writetable(T,'youtxtfile.txt')

More Answers (1)

Walter Roberson
Walter Roberson on 1 Aug 2019
Nc = [CT(1), num2cell(CT{2}), CT(3), num2cell(CT{4}), num2cell(CT{5})];
writecell(Nc, filename)
This requires r2019a or later, but we know that you have that because writematrix is introduced at the same time.
  9 Comments
Ivan Mich
Ivan Mich on 2 Aug 2019
i gave the command you suggested me , dbstop if error, and command window show me this message :
Error in test_v2_pro (line 85) Nc = [CT(1:1), num2cell(CT{2:1}), CT(3:1), num2cell(CT{4:1}), num2cell(CT{5:1})];
The same message is shown when i am trying to use the commands:
Nc = [CT(1), num2cell(CT{2}), CT(3), num2cell(CT{4}), num2cell(CT{5})]
Nc = [CT(1), num2cell(CT{2}), CT(3), num2cell(CT{4})]
Nc = [CT(1), num2cell(CT{2}), CT(3)]
Nc = [CT(1), num2cell(CT{2})]
Nc = [CT(1)]
Actually, I have to notice that my data are coming from .csv files. I don't know if this could help you to give some advice...
Walter Roberson
Walter Roberson on 13 Aug 2019
It is not possible to get that error from
Nc = [CT(1)]
But in the meantime, please tell use more about CT{3} which your display indicates is a cell array.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!