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 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

Guillaume
Guillaume am 8 Okt. 2014
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 Kommentare
pengcheng
pengcheng am 8 Okt. 2014
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 am 8 Okt. 2014
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);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by