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!