Converting Cell Array into Array

37 ビュー (過去 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{:})
  1 件のコメント
MByk
MByk 2019 年 1 月 11 日
Thank you both.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by