Extract arrays from cell with order in a for loop
Ältere Kommentare anzeigen
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 Kommentare
the cyclist
am 24 Mai 2021
Bearbeitet: the cyclist
am 24 Mai 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
am 24 Mai 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
am 25 Mai 2021
Akzeptierte Antwort
Weitere Antworten (1)
David Hill
am 24 Mai 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 Kommentar
Görkem Bam
am 25 Mai 2021
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!