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 CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by