how do you create an array of 3d arrays

44 vues (au cours des 30 derniers jours)
JG
JG le 15 Oct 2021
Modifié(e) : Matt J le 15 Oct 2021
I have a stack of images that are organized by row x column x images in stack to form a 3d array e.g. 10x 10 x 100. This would be 100 frame stack of 10 x 10 images. I need to create an array of them. For example 10 x 10 x 100 x 15 would be 15 image stacks where there are 100 10x10 images in each stack. I've been trying different ways of using the cat function but without any luck.

Réponses (2)

Matt J
Matt J le 15 Oct 2021
Modifié(e) : Matt J le 15 Oct 2021
I've been trying different ways of using the cat function
You haven't told us in what form the 15 stacks exist now. If you have the stacks as 15 separate variables currently in your workspace then the cat() function is indeed the thing to use, e.g.,
A=cat(4, stack1,stack2,...,stack15)
If you expect to generate these stacks over the course of the loop, you could just pre-allocate the 4D array that will hold them.
A=nan(10,10,100,15);
for i=1:15
A(:,:,:,i)=... %compute something
end

JG
JG le 15 Oct 2021
I kept tinkering and figured it out.
all_stacks = cat(4, all_stacks, one_stack)
where one_stack is a 10 x 10 x 100 stack of images.
My biggest problem was trying to add each frame one-at-a-time instead of assembling the 10x10x100 stack separately and then adding it as a complete unit.
  1 commentaire
Matt J
Matt J le 15 Oct 2021
Modifié(e) : Matt J le 15 Oct 2021
It is highly inadvisable to do it that way. Lots of extra memory allocation...

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by