I save a cellarry ,but the result looks like strange

1 visualizzazione (ultimi 30 giorni)
S{1}
ans =
'4400002970000003533' '8500000190000013093'
'4400002970000003533' '8500000190000045501'
'4400002970000003533' '8500000840000005660'
'4400002970000003533' '8500000840000006008'
csvwrite('s1.csv',S{1}); but when i open the file , the result is like this 4,4,0,0,0,0,2,9,7,0,0,0,0,0,0,3,5,3,3,8,5,0,0,0,0,0,1,9,0,0,0,0,0,1,3,0,9,3 4,4,0,0,0,0,2,9,7,0,0,0,0,0,0,3,5,3,3,8,5,0,0,0,0,0,1,9,0,0,0,0,0,4,5,5,0,1 4,4,0,0,0,0,2,9,7,0,0,0,0,0,0,3,5,3,3,8,5,0,0,0,0,0,8,4,0,0,0,0,0,0,5,6,6,0 4,4,0,0,0,0,2,9,7,0,0,0,0,0,0,3,5,3,3,8,5,0,0,0,0,0,8,4,0,0,0,0,0,0,6,0,0,8 do you konw why? can you help me? thanks

Risposta accettata

Geoff Hayes
Geoff Hayes il 15 Ott 2014
Remember that your strings are just arrays of characters. So when you export the array to file using csvwrite, a comma will be inserted between each element in the array - so a comma between each character.
You may want to consider an alternative method to export cell array data to a text file. From this example, you could do
% open the file
fid = fopen('s1.csv','wt+');
if fid>0
% write each row to file
V = S{1}; % assumes that V is a cell array
for k=1:size(V,1)
fprintf(fid,'%s,%s\n',V{k,:});
end
fclose(fid);
end
Now, when you open the s1.csv file, you will see
4400002970000003533,8500000190000013093
4400002970000003533,8500000190000045501
4400002970000003533,8500000840000005660
4400002970000003533,8500000840000006008
which is probably what you would like.

Più risposte (1)

Andrew Reibold
Andrew Reibold il 15 Ott 2014
Modificato: Andrew Reibold il 15 Ott 2014
Read the documentation... Haha
"csvwrite does not accept cell arrays for the input matrix. To export cell arrays to a text file, use low-level functions such as PRINTF."
Using cell arrays will result in every character being split

Community Treasure Hunt

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

Start Hunting!

Translated by