How to write this cell to a csvfile?

Hi all, If I have a cell with contents like
{'X','Y';
1,'a';
2,'c';
3,'c'}
Now I want to convert this cell to a csvfile like below:
X,Y
1,a
2,c
3,c
How to do this using csvwrite.

답변 (1개)

DEVANAND
DEVANAND 2014년 4월 4일

0 개 추천

OK I did it. This is how I did:
fid = fopen('junk.csv','w');
fprintf(fid,'%s,%s\n',xx{1,:}); % cell name xx with 4*2 elements
for i = 2:4
fprintf(fid,'%d,%s\n',xx{i,:});
end
fclose(fid);

댓글 수: 2

Alternative without a loop:
xxt = xx(2:4, :)';
fprintf(fid,'%d,%s\n',xxt{:});
DEVANAND
DEVANAND 2014년 4월 4일
This is a better solution. Thank you.

이 질문은 마감되었습니다.

제품

태그

질문:

2014년 4월 4일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by