writing values from cell array to txt file
显示 更早的评论
Hello,
I have a cell array let say of items containing 5 separate lists of items (so, my cell array size is 5x5, each cell containing 5 items). I want to write each list (cell) into a separate txt file.
After browsing over the forum, I came up with this code but it complains about using fprintf with cell input, giving this error: ??? Error using ==> fprintf Function is not defined for 'cell' inputs.
My code is:
for k=1:5
textFilename = ['file' num2str(k) '.txt'];
fid = fopen(textFilename, 'w');
if fid == -1
error('Cannot open file: %s', textFilename);
end
fprintf(fid,'%s',dummy_list(:,k));
end
Can someone please tell me how to accomplish this? I know the hard way is to have another for loop that goes over all the rows for each cell.
Thank you in advance.
8 个评论
Oleg Komarov
2012-8-9
Is each cell a cell array or a char aray? In other words, dummy_list{1} is a cell array of 5 strings?
S
2012-8-9
Yash
2012-8-9
can you convert the cell array?
S
2012-8-9
Feng
2012-8-9
try to use {}, rather than () to access the content of teh cell, like dummy_list{:,k}
S
2012-8-9
Honglei Chen
2012-8-9
Can you give an example of your dummy_list, is it something like this?
c = {{'hello' 'yes'} {'no', 'goodbye'}}
and you want to print each entry separately like
hello
yes
S
2012-8-9
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!