i want to save cell data as csv format ,but il shows there is a error,how can i save these cell array as csv format? thanks

2 次查看(过去 30 天)
S =
{ 19x2 cell}
{ 3x2 cell}
{ 1x2 cell}
{ 10x2 cell}
{ 1x2 cell}
[]
[]
{ 6x2 cell}
{ 210x2 cell}
[]
{ 13041x2 cell}
{ 15x2 cell}
{ 91x2 cell}
[]
{ 6x2 cell}
{ 1x2 cell}
{ 1x2 cell}
{ 66x2 cell}
{ 1x2 cell}
{ 496x2 cell}
[]
{ 66x2 cell}
S{1}=ans =
'4400002970000003533' '8500000190000013093'
'4400002970000003533' '8500000190000045501'
'4400002970000003533' '8500000840000005660'
'4400002970000003533' '8500000840000006008'
'4400002970000003533' '8500090100000000354'
'4400002970000003533' '8500090100000007316'
'4400002970000003533' '8500090100000009112'
'4400002970000003533' '8500090100000010547'
'8500000190000013093' '8500000190000045501'
'8500000190000013093' '8500000840000005660'
'8500000190000013093' '8500000840000006008'
'8500000190000013093' '8500090100000000354'
'8500000190000013093' '8500090100000007316'
'8500000190000013093' '8500090100000009112'
'8500000190000013093' '8500090100000010547'
'8500000190000045501' '8500000840000005660'
'8500000190000045501' '8500000840000006008'
'8500000190000045501' '8500090100000000354'
'8500000190000045501' '8500090100000007316'
I use csvwrite('lpc.csv',S),but it doesn't work and il always shows a error, anyone can help me ? thanks

回答(3 个)

Orion
Orion 2014-10-13
Hi,
The problem is that you have a cell inside a cell, so you can't write it in a csvfile. it will mean that you create a text file in a text file, which is a nonsense.
with your example, you can use csvwrite as
csvwrite('lpc.csv',S{1}) % only the first cell of your cell.
if you need to save all the informations inside the cell S, you should consider creating a loop like
for i = 1:length(S)
csvwrite(sprintf('lpc_S%d.csv',i),S{i});
end
and so each csv file will contain the ith cell of the original cell S.

Sean de Wolski
Sean de Wolski 2014-10-13

per isakson
per isakson 2014-10-13
The function Cell Array to CSV-file by Jerry might write your cell array to a "csv" file.

Community Treasure Hunt

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

Start Hunting!

Translated by