Help me print this cell array...
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
David Pesetsky
el 27 de Jun. de 2018
Comentada: Star Strider
el 27 de Jun. de 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 comentarios
Respuesta aceptada
Star Strider
el 27 de Jun. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!