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에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!