I save a cellarry ,but the result looks like strange
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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.
0 个评论
更多回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!