How to combine cells from cell array with a loop

17 views (last 30 days)
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 Comments
Bruno Luong
Bruno Luong on 27 Jul 2020
Edited: Bruno Luong on 27 Jul 2020
Have you tried (no loop)
ALLCELL = cell2mat(data(:));
Or
ALLCELL = cat(1, data{:});

Sign in to comment.

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 27 Jul 2020
data{1}=magic(3);
data{2}=rand(2,3);
data{3}=ones(4,3);
cell2mat(data.')

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!