writing values from cell array to txt file
Show older comments
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 Comments
Oleg Komarov
on 9 Aug 2012
Is each cell a cell array or a char aray? In other words, dummy_list{1} is a cell array of 5 strings?
S
on 9 Aug 2012
Yash
on 9 Aug 2012
can you convert the cell array?
S
on 9 Aug 2012
Feng
on 9 Aug 2012
try to use {}, rather than () to access the content of teh cell, like dummy_list{:,k}
S
on 9 Aug 2012
Honglei Chen
on 9 Aug 2012
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
on 9 Aug 2012
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!