I save a cellarry ,but the result looks like strange

1 回表示 (過去 30 日間)
pengcheng
pengcheng 2014 年 10 月 15 日
編集済み: Andrew Reibold 2014 年 10 月 15 日
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

採用された回答

Geoff Hayes
Geoff Hayes 2014 年 10 月 15 日
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.

その他の回答 (1 件)

Andrew Reibold
Andrew Reibold 2014 年 10 月 15 日
編集済み: Andrew Reibold 2014 年 10 月 15 日
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

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by