Help me print this cell array...
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
David Pesetsky
il 27 Giu 2018
Commentato: Star Strider
il 27 Giu 2018
I've attached a cell array to this post. Can ANYONE help me just print it to a comma delimet file? Or text file is fine. Will always have 3 columns. Could have a few more rows.
Thank you!
0 Commenti
Risposta accettata
Star Strider
il 27 Giu 2018
The problem is the first column, a cell containing a cell containing a string. The loop is necessary because that is the only way to use fprintf to produce lines of different variable types.
Try this:
D = load('report.mat');
C = D.report;
fid = 1; % This Prints To The Command Window, Use ‘fopen’ In Your Code
for k1 = 1:size(C,1)
str = C{k1,1}{:};
fprintf('%s,%f,%f\n', str,C{k1,2},C{k1,3})
end
fprintf(fid,'\n')
fclose(fid);
producing:
GI,0.361775,25128.000000
GK,0.368588,41753.000000
HG,0.468290,25128.000000
Change the numeric format descriptors as necessary. You can of course eliminate the separate ‘str’ variable and use the fprintf call as:
fprintf('%s,%f,%f\n', C{k1,1}{:}, C{k1,2}, C{k1,3})
You will have to use textscan to read it.
2 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Characters and Strings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!