Saving cell array with strings to a text file.

5 次查看(过去 30 天)
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.

回答(1 个)

Matt Fig
Matt Fig 2012-11-4
编辑:Matt Fig 2012-11-4
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...

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by