How to combine cells from cell array with a loop

13 ビュー (過去 30 日間)
Ko Fa
Ko Fa 2020 年 7 月 27 日
コメント済み: Ko Fa 2020 年 7 月 27 日
I have a cell array with 200 cells called data. Each cell contains a matrix NxM. M is the same on every cell. I am trying to get everything in one cell/vector.
What I did:
for i = 1:1:200
C = cell2mat(data(i))
end
This does give me all the outputs needed, but how can I assign automatic Variables to every output, so that I can get them all in on cell with
ALLCELL = [C1:C200]
Greatly appreciate any help.
  2 件のコメント
Bruno Luong
Bruno Luong 2020 年 7 月 27 日
編集済み: Bruno Luong 2020 年 7 月 27 日
Have you tried (no loop)
ALLCELL = cell2mat(data(:));
Or
ALLCELL = cat(1, data{:});
Ko Fa
Ko Fa 2020 年 7 月 27 日
Thank you, it works!

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

採用された回答

Fangjun Jiang
Fangjun Jiang 2020 年 7 月 27 日
data{1}=magic(3);
data{2}=rand(2,3);
data{3}=ones(4,3);
cell2mat(data.')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by