Converting Cell Array into Array

조회 수: 28 (최근 30일)
MByk
MByk 2019년 1월 11일
편집: MByk 2020년 6월 25일
I have 4 matrices with fixed columns but different rows (4 * n-by-3) created inside a for loop. I am storing them in a cell array but I cant convert it into array using "cell2mat" function. Is there way to convert the cell array or a better way to store the results may be without any cell to array conversion? Thanks for the help.
for i=1:4
% Some calculations here
rSet = ...
C{i,1} = {rSet};
end
cell2mat(C);
% Error using cell2mat (line 52)
% CELL2MAT does not support cell arrays containing cell arrays or objects.

채택된 답변

madhan ravi
madhan ravi 2019년 1월 11일
편집: madhan ravi 2019년 1월 11일
C=cell(1,4); % Preallocate before loop
C{i}...
% ^-—- is enough
vertcat(C{:}) %outside loop% or
[C{:}]

추가 답변 (1개)

Stephen23
Stephen23 2019년 1월 11일
for i=1:4
% Some calculations here
rSet = ...
C{i,1} = rSet;
end
vertcat(C{:})

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by