Help me print this cell array...
조회 수: 9 (최근 30일)
이전 댓글 표시
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
채택된 답변
Star Strider
2018년 6월 27일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!