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

madhan ravi
madhan ravi 2019년 8월 1일
편집: madhan ravi 2019년 8월 1일
please attach your data as .mat file
For converting cell arras to double array, you could use cell2mat:
Luna
Luna 2019년 8월 1일
To answer this, we must see what is inside the cell array. Could you please share it?

댓글을 달려면 로그인하십시오.

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 8월 2일

1 개 추천

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')

추가 답변 (1개)

Walter Roberson
Walter Roberson 2019년 8월 1일

0 개 추천

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

Ivan Mich
Ivan Mich 2019년 8월 1일
I used this command you suggested me, but unfortunately it doesn't works. The command wimndow wrote me these:
Error in test_v2_pro (line 85)
Nc = [CT(1), num2cell(CT{2}), CT(3), num2cell(CT{4}), num2cell(CT{5})];
Why ?
Ivan Mich
Ivan Mich 2019년 8월 1일
편집: Ivan Mich 2019년 8월 1일
Also I've tried the command:
Nc = [CT(1,1), num2cell(CT{2,1}), CT(3,1), num2cell(CT{4,1}), num2cell(CT{5,1})];
writecell(Nc, 'filename.txt')
And it doesn't work too...
The command window showed me :
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})];
ALSO , I ve tried these command :
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})];
and it doesn't work too...
Do you have any idea why?
Thank you
madhan ravi
madhan ravi 2019년 8월 1일
편집: madhan ravi 2019년 8월 1일
Could you attach your file as .mat ? , asking it for the second time.
Ivan Mich
Ivan Mich 2019년 8월 1일
I am sorry but i can't share this file..
We need the full error message showing what matlab thinks is wrong.
Ivan Mich
Ivan Mich 2019년 8월 1일
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})];
This is the full error message that command Window shows. This message is the same when I use the previous command I refer. Command Window does not shows me something else...
At the command line give the command
dbstop if error
and then run the code. When the problem occurs, try these and see which ones give an error and show us the error:
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)]
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...
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2019년 8월 1일

댓글:

2019년 8월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by