Create a 3D cell with vector elements of size 1x5 from five 3D matrices
Show older comments
Hello!
I have a structure of five 3D images (double,size 181x213x41). I would like to create a cell from this data, of same size as the 3D images (181x213x41) where each element will be a vector of size 1x5. I.e. the first vector element comes from 3D image 1, the second element from 3D image 2 and so on.
Example:
cellImage{i,j,k} = [1 2 4 1 0];
where
structure(1).image(i,j,k) = 1
structure(2).image(i,j,k) = 2
structure(3).image(i,j,k) = 4
structure(4).image(i,j,k) = 1
structure(5).image(i,j,k) = 0
I can do this by looping:
for i = 1:5
for j = 1:181
for k = 1:213
for l = 1:41
cellImage{j,k,l}(i) = structure(i).image(j,k,l);
end
end
end
end
This takes a very long time however. I want something similar to below (but that doesn't work).
for i = 1:5
cellImage{:,:,:}(i) = structure(i).image(:,:,:);
end
Does anyone know of a better way of doing this?
Thank you!
Accepted Answer
More Answers (0)
Categories
Find more on Logical 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!