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!