フィルターのクリア

Creating a 3D array out of multiple 2D arrays

205 ビュー (過去 30 日間)
Med_Imager
Med_Imager 2012 年 2 月 13 日
コメント済み: Steven Lord 2021 年 3 月 22 日
I have 10 masks that are 256 x 256 each. These masks are for 10 respective slices, so I want to combine them and make a 3D array ( 256x256x10). How do I do this? Ideas? Thanks!

採用された回答

Sean de Wolski
Sean de Wolski 2012 年 2 月 13 日
cat(3,mask1,mask2,...)
doc cat %for more info
  2 件のコメント
Safwana Razak
Safwana Razak 2021 年 3 月 22 日
hi, what if i got > 100 array in 3rd array, how to automate it?
cat(3,mask1,.....mask100)
Steven Lord
Steven Lord 2021 年 3 月 22 日
Revise your code so it doesn't create 100 individual variables. Preallocate the array to be the desired size from the start and fill it in.
A = magic(4);
B = repmat(A, [1 1 5]); % or
C = zeros(4, 4, 5);
for k = 1:5
B(:, :, k) = A^k;
C(:, :, k) = A^k;
end

サインインしてコメントする。

その他の回答 (2 件)

Med_Imager
Med_Imager 2012 年 2 月 13 日
You can also do
Mask_3D(:,:,1)=Mask_1
for index=1:10
eval(['Mask_3D(:,:,index)=Mask_' num2str(index)';']);
end

Kris Hoffman
Kris Hoffman 2020 年 7 月 20 日
I just had this exact problem (even with the same dimensions)
If the masks are all in one cell array,
A = cat(3,YourMaskArrayHere{:})
Produces a 256x256x10 uint16 array.

Community Treasure Hunt

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

Start Hunting!

Translated by