How to export a cell array, into excel, with elements of different sizes
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
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
채택된 답변
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
Thank you very much, the code is correct!
Hannah Bartlett
2019년 7월 25일
편집: Hannah Bartlett
2019년 7월 25일
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

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.
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
Can you attach your cell array in a .mat file?
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)
