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 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Guillaume
on 8 Oct 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 Comments
Guillaume
on 8 Oct 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);
More Answers (0)
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!