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
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!