Saving cell array with strings to a text file.
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I'm trying to figure out how to save a chart to a text file. The 'chart' is a cell array that consists of strings. So I have:
a = {'zdfsad' 'xdads' 'zdfsad' 'xdads' 'zdfsad' 'xdads';...
'shs' 'asdbjv' 'affsa' 'asakj' 'asdbjv' 'affsa';...
'zdfsad' 'xdads' 'zdfsad' 'asdbjv' 'affsa' 'zdfsad'}
fid = fopen('output','w');
fprintf(fid, 'title\n\n');
fprintf(fid, a{:});
fclose(fid);
But when I run it and use the 'type output' command it merely returns:
title
zdfsad
I'm pretty sure the issue is with my fprintf command but I can't for the life of me figure out how to use it with a cell array containing strings.
Thanks for your help.
0 Kommentare
Antworten (1)
Matt Fig
am 4 Nov. 2012
Bearbeitet: Matt Fig
am 4 Nov. 2012
a = {'zdfsad' 'xdads' 'zdfsad' 'xdads' 'zdfsad' 'xdads';...
'shs' 'asdbjv' 'affsa' 'asakj' 'asdbjv' 'affsa';...
'zdfsad' 'xdads' 'zdfsad' 'asdbjv' 'affsa' 'zdfsad'}
fid = fopen('output.txt','w');
fprintf(fid, 'title\n\n');
str = [repmat('%10s',1,size(a,2)),'\n'];
for ii = 1:size(a,1)
fprintf(fid,str,a{ii,:});
end
fclose(fid);
Now open the file with wordpad...
1 Kommentar
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!