Writing cell array with inconsistent size cells to txt

I have an 1818x1 cell array (attached) that is set up like this:
[2,4,1,3]
[3]
[3,4,2,1,4]
...
I want to write this to a text file (or anything that will open in excel really) where each value of each cell in the array is given it's own cell in Excel per row. That's not particularly well explained I think so I've attached an example desired output excel file.
I found code in the help section but I can't figure out how to write all values of a single cell and then move to the next row. This is what I've been using:
>> fileID = fopen('celldata.dat','w');
>> formatSpec = '%d\n';
>> [nrows,ncols] = size(allAreasV);
for row = 1:nrows
fprintf(fileID,formatSpec,allAreasV{row,:});
end
>> fclose(fileID);
I guess it's a formatSpec problem but I'm not sure what I need to write there.

 Accepted Answer

[fid,msg] = fopen('celldata.csv','wt');
assert(fid>=3,msg)
for k = 1:numel(allAreasV)
fprintf(fid,'%d,',allAreasV{k});
fprintf(fid,'\n');
end
fclose(fid);
The CSV file it creates is attached, and looks like this in Excel:

More Answers (0)

Products

Release

R2018a

Asked:

on 30 Jul 2018

Commented:

on 30 Jul 2018

Community Treasure Hunt

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

Start Hunting!