Filter löschen
Filter löschen

Help me print this cell array...

1 Ansicht (letzte 30 Tage)
David Pesetsky
David Pesetsky am 27 Jun. 2018
Kommentiert: Star Strider am 27 Jun. 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!

Akzeptierte Antwort

Star Strider
Star Strider am 27 Jun. 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 Kommentare
David Pesetsky
David Pesetsky am 27 Jun. 2018
Thank you. This worked.
Star Strider
Star Strider am 27 Jun. 2018
As always, my pleasure.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by