Exporting cell arrays with different sizes to excel

조회 수: 3 (최근 30일)
monika roopak
monika roopak 2018년 10월 3일
댓글: Bob Thompson 2018년 10월 4일
I have cell array of size 774 X1 , and each array has another of one row and varying number of column. so my question is how i can export data from this cell array to a excel file.

채택된 답변

Bob Thompson
Bob Thompson 2018년 10월 3일
What kind of data is contained within the inner cells? If there are more arrays I think you will likely have some problems. Here is what I thought of for a first attempt.
Cell = % Your cell with data
[row,col] = size(Cell);
for k = 1:row;
lengths(row) = size(Cell{k},2);
end
col = max(lengths)
Block = cell(row,col);
for k = 1:row;
Block{k,1:size(Cell{k},2)} = Cell{k};
end
Theoretically, this will "bump" the contents of each cell up a level, so that you have a new cell matrix that doesn't contain further matrices, and you can print it to a 2D excel range.
You might also look at cell2mat for cell arrays that contain doubles.
  댓글 수: 2
monika roopak
monika roopak 2018년 10월 4일
편집: monika roopak 2018년 10월 4일
ERROR :Expected one output from a curly brace or dot indexing expression, but there were 20 results. Data in each array with in cell array is are numbers like 28, 21,8,5....
Bob Thompson
Bob Thompson 2018년 10월 4일
One mistake I made (not that it's causing the error) is that it should be lengths(k) not lengths(row).
Since it's just arrays of doubles (numbers) you can use this:
[row,col] = size(CELL);
for k = 1:row;
lengths(k) = size(CELL{k},2);
end
col = max(lengths)
Block = nan(row,col);
for k = 1:row;
Block(k,1:size(CELL{k},2)) = CELL{k};
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by