How to export a Matlab cell array to an Excel spreadsheet?
Mostrar comentarios más antiguos
I have a cell array X={'A','B','C','D',A,B,C,D} where A,B,C and D are column vectors of equal size. I intended to create a spreadsheet by: >>xlswrite('X.xls',X) but I didnt get the values of the vectors in my spreadsheet. Maybe I didn't create the cell array properly (when I display the cell array, I get: >> X X =
'A' 'B' 'C' 'D'
{241x1 cell} {241x1 cell} {241x1 cell} {241x1 cell}
Can anyone provide any suggestions? Thanks.
Respuesta aceptada
Más respuestas (2)
Image Analyst
el 24 de Nov. de 2013
It looks like A, B, C, and D are actually cell arrays, not regular numerical arrays. How did you create A, B, C, and D? Did you put braces around them when you created them? If so, you don't want to do that.
A = rand(5); % OK. A is a double array.
A = {rand(5)}; % Not okay - A is now a cell.
3 comentarios
Rinu
el 24 de Nov. de 2013
Image Analyst
el 24 de Nov. de 2013
Yeah you're right. Now that I think about it, it can write out a numerical array, but if you're going to combine them (strings plus numbers) then you need to have one big cell array where each cell is just one number (element) from the numerical array, not the whole array. So you'd need to do
ca = cell(25, 4);
ca{1,1} = 'A';
ca{1,2} = 'B';
ca{1,3} = 'C';
ca{,14} = 'D';
for k = 2:25
ca{1, k} = A(k-1);
ca{2, k} = B(k-1);
ca{3, k} = C(k-1);
ca{4, k} = D(k-1);
end
Rinu
el 24 de Nov. de 2013
João Araújo
el 18 de Oct. de 2017
1 voto
I have a follow up question. I'm looking to organize some data, and I have a cell array with some names. The cells aren't necessarily the same size, since I can have 5 names in one cell and 12 in the next. I have a total of 1783 cells, so I'm looking for an automated way to solve this issue. How can I export this cell array to an excel spreadsheet?
Categorías
Más información sobre Cell Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!