i want to use the fonction (csvwrite) to write S into a fiche csv,but i get a result like this,anyone can help me? thank you

1 次查看(过去 30 天)
S =
'4400000570000000008' '4400000570000000013'
'4400000570000000001' '4400000570000000014'
'4400000570000000003' '4400000570000000006'
'4400000570000000000' '4400000570000000010'
'4400000570000000002' '4400000570000000006'
'4400000570000000002' '4400000570000000007'
'4400000570000000002' '4400000570000000008'
'4400000570000000007' '4400000570000000008'
'4400000570000000004' '4400000570000000007'
'4400000570000000001' '4400000570000000012'
'4400000570000000001' '4400000570000000013'
'4400000570000000012' '4400000570000000013'
csvwrite('cilpc.csv',S,0,0);
4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,0,8,4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,1,3 4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,0,1,4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,1,4 4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,0,3,4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,0,6 4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,0,0,4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,1,0 4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,0,2,4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,0,6 4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,0,2,4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,0,7 4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,0,2,4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,0,8 4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,0,7,4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,0,8 4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,0,4,4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,0,7 4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,0,1,4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,1,2 4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,0,1,4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,1,3 4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,1,2,4,4,0,0,0,0,0,5,7,0,0,0,0,0,0,0,0,1,3

采纳的回答

Guillaume
Guillaume 2014-10-8
You can't use csvwrite for this. It's fairly simple with low level functions anyway:
fid = fopen('cilpc.csv', 'wt');
for row = 1: size(S, 1)
fprintf(fid, '%s\n', strjoin(S(row, :), ','));
end
fclose(fid);
  7 个评论
pengcheng
pengcheng 2014-10-8
fid = fopen('cimal.csv', 'wt');
for row = 1: size(S, 1)
fprintf(fid, '%s,', S{row});
fprintf(fid, '%s\n', S{row, end});
end
fclose(fid);
It works ,thank you very much
Guillaume
Guillaume 2014-10-8
The code you've posted works as long as S is only two columns. If that is the case, you could just replace the two fprintf with one:
fprintf(fid, '%s,%s\n', S{row, 1}, s{row, 2});
For reference, a code that will work regardless of the number of columns in S:
fid = fopen('cilpc.csv', 'wt');
for row = 1:size(S, 1)
for col = 1:size(S, 2)-1;
fprintf(fid, '%s,', S{row, col});
end
fprintf(fid, '%s\n', S{row, end});
end
fclose(fid);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by