Extract arrays from cell with order in a for loop
Show older comments
Hi,
I want to build a for loop which will extract cell datas into arrays (or matrices) . Let's say i got a cell A with the size of 1x12 and each cell in A has size of 25x1 array.
So is it possible to build a loop like this, (I'd like to name new array after its sequence in the for loop)
t = size(A,2);
for j=1:t
array_j = A{j};
end
or is there any other easy way to extract each cell into different arrays?
Thanks,
Görkem
3 Comments
the cyclist
on 24 May 2021
Edited: the cyclist
on 24 May 2021
May I ask why you want to do this, since it seems like a terrible idea. I don't believe there is anything you can do with variable array_j that you can't do with A{j}. Dynamically named variables are a bad idea in general. See this explanation why.
It also seems you could just use one multidimensional numeric array.
Stephen23
on 24 May 2021
"I'd like to name new array after its sequence in the for loop"
Naming arrays dynamically is one way that beginners force themselves into writing slow, inefficient, complex code:
Your code will be simpler and much more efficient if you use indexing, just like MATLAB was designed for.
"...is there any other easy way to extract each cell into different arrays"
The content of that cell array are already different arrays.
Görkem Bam
on 25 May 2021
Accepted Answer
More Answers (1)
David Hill
on 24 May 2021
t = size(A,2);
for j=1:t
newArray(j,:) = A{j}';%better to put into a matrix and just index into it than create a whole bunch of variable names
end
1 Comment
Görkem Bam
on 25 May 2021
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!