How to export a cell array, into excel, with elements of different sizes
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
I have a cell whose cells are vector of different sizes. As an example:
cell ={[50x1 double] [32x1 double] [288x1 double]}
How do I export this into an excel file, and in each column of the excel file goes a vector? I only could make with one element of the cell, because of the different sizes of the contents of the cell.
Thanks already
Accepted Answer
Image Analyst
on 28 Feb 2014
You have to extract the arrays from each cell and put them into individual cells. So, for example with the first cell, you need to do something like
theArray = originalCellArray{1}; % Extract first cell.
ca = cell(288,3);
for row = 1 : size(theArray, 1)
ca{row,1} = theArray(row);
end
Do that for each of your 3 cells. You can have them all in one cell.
theArray = originalCellArray{2}; % Extract second cell.
for row = 1 : size(theArray, 1)
ca{row,2} = theArray(row);
end
theArray = originalCellArray{3}; % Extract third cell.
for row = 1 : size(theArray, 1)
ca{row,3} = theArray(row);
end
xlswrite(filename, ca);
You might want to read this before you start (in case I programmed something up incorrectly - I didn't test it): http://matlab.wikia.com/wiki/FAQ?title=FAQ&cb=8838#What_is_a_cell_array.3F
5 Comments
Carlos Lobato
on 28 Feb 2014
Thank you very much, the code is correct!
Hannah Bartlett
on 25 Jul 2019
Edited: Hannah Bartlett
on 25 Jul 2019
I have a lot more columns in my array of arrays (26), but I can't get my for loop to work! Any ideas?
The code below just gives the final column, with blank cells for the first 5 * 25.
for col = 1 : 26
theArray = output_matrix1{col};
xx = cell(5,26);
for row = 1 : size(theArray, 1)
xx{row,col} = theArray(row);
end
end

Image Analyst
on 25 Jul 2019
Hannah, what are you trying to do? Start your own question and attach xx and output_matrix1 and any other needed variables in a .mat file.
Hannah Bartlett
on 26 Jul 2019
Hi,
I am trying to do the same as Carlos, but because I have a 1x26 array, each containing 5x1 vectors, it would be nice to have a for loop.
I needed the data so followed your method above but would like help with a for loop for my write up if you have any ideas.
My question:
My current code is bulky! Eep... But my for loop doesn't work.
% Image Analyst, 2014
% https://uk.mathworks.com/matlabcentral/answers/119476-how-to-export-a-cell-array-into-excel-with-elements-of-different-sizes#comment_728470
theArray = output_matrix1{1}; % Extract first column.
xx = cell(5,26);
for row = 1 : size(theArray, 1)
xx{row,1} = theArray(row);
end
theArray = output_matrix1{2}; % Extract second column.
for row = 1 : size(theArray, 1)
xx{row,2} = theArray(row);
end
theArray = output_matrix1{3}; % Extract third column.
for row = 1 : size(theArray, 1)
xx{row,3} = theArray(row);
end
theArray = output_matrix1{4}; % Extract fourth column.
for row = 1 : size(theArray, 1)
xx{row,4} = theArray(row);
end
theArray = output_matrix1{5}; % Extract fifth column.
for row = 1 : size(theArray, 1)
xx{row,5} = theArray(row);
end
theArray = output_matrix1{6};
for row = 1 : size(theArray, 1)
xx{row,6} = theArray(row);
end
theArray = output_matrix1{7};
for row = 1 : size(theArray, 1)
xx{row,7} = theArray(row);
end
theArray = output_matrix1{8};
for row = 1 : size(theArray, 1)
xx{row,8} = theArray(row);
end
theArray = output_matrix1{9};
for row = 1 : size(theArray, 1)
xx{row,9} = theArray(row);
end
theArray = output_matrix1{10};
for row = 1 : size(theArray, 1)
xx{row,10} = theArray(row);
end
theArray = output_matrix1{11};
for row = 1 : size(theArray, 1)
xx{row,11} = theArray(row);
end
theArray = output_matrix1{12};
for row = 1 : size(theArray, 1)
xx{row,12} = theArray(row);
end
theArray = output_matrix1{13};
for row = 1 : size(theArray, 1)
xx{row,13} = theArray(row);
end
theArray = output_matrix1{14};
for row = 1 : size(theArray, 1)
xx{row,14} = theArray(row);
end
theArray = output_matrix1{15};
for row = 1 : size(theArray, 1)
xx{row,15} = theArray(row);
end
theArray = output_matrix1{16};
for row = 1 : size(theArray, 1)
xx{row,16} = theArray(row);
end
theArray = output_matrix1{17};
for row = 1 : size(theArray, 1)
xx{row,17} = theArray(row);
end
theArray = output_matrix1{18};
for row = 1 : size(theArray, 1)
xx{row,18} = theArray(row);
end
theArray = output_matrix1{19};
for row = 1 : size(theArray, 1)
xx{row,19} = theArray(row);
end
theArray = output_matrix1{20};
for row = 1 : size(theArray, 1)
xx{row,20} = theArray(row);
end
theArray = output_matrix1{21};
for row = 1 : size(theArray, 1)
xx{row,21} = theArray(row);
end
theArray = output_matrix1{22};
for row = 1 : size(theArray, 1)
xx{row,22} = theArray(row);
end
theArray = output_matrix1{23};
for row = 1 : size(theArray, 1)
xx{row,23} = theArray(row);
end
theArray = output_matrix1{24};
for row = 1 : size(theArray, 1)
xx{row,24} = theArray(row);
end
theArray = output_matrix1{25};
for row = 1 : size(theArray, 1)
xx{row,25} = theArray(row);
end
theArray = output_matrix1{26};
for row = 1 : size(theArray, 1)
xx{row,26} = theArray(row);
end
Image Analyst
on 26 Jul 2019
Can you attach your cell array in a .mat file?
More Answers (0)
Categories
Find more on Spreadsheets in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)