Saving cell array with strings to a text file.
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Matt Fig
le 4 Nov 2012
Modifié(e) : Matt Fig
le 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 commentaire
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!