I have a 19x256x256 STM image in an array form that I need to transform
1 view (last 30 days)
Show older comments
I want to take my 19x256x256 array and write into 256 separate matrices, which I think can be done using reshape. I also want to write each matrix automatically into a new "layer" i.e. plane1=A(:,:,1), plane2=A(:,:,2),....,plane256=A(:,:,256). Is there a way of doing this with some sort of looping so that each new variable is stored automatically?
2 Comments
the cyclist
on 18 Jun 2018
Edited: the cyclist
on 18 Jun 2018
It is almost always a terrible idea to a series of variables with V1, V2, ... V256. There is a detailed list of why it is a bad idea in this answer.
What are you trying to do, that makes you think that referencing plane256 is better than referencing A(:,:,256)? There is almost certainly a better way.
Accepted Answer
the cyclist
on 18 Jun 2018
Using a cell array, with one element for each matrix, would be a much more sane way to do something like what you are asking for
N = 256;
A_cell = cell(N,1);
for nc = 1:N
A_cell{nc} = A(:,:,nc);
end
Then you can reference A_cell{137} in the same way you want to reference the variable plane137. But it is not clearly better to me that simply referencing A(:,:,137).
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!