Info

此问题已关闭。 请重新打开它进行编辑或回答。

How to write this cell to a csvfile?

1 次查看(过去 30 天)
DEVANAND
DEVANAND 2014-4-4
关闭: MATLAB Answer Bot 2021-8-20
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
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 个评论
Jan
Jan 2014-4-4
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.

此问题已关闭。

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by