Export 2 Dimension out of a 3 dimensionoal Array
1 次查看(过去 30 天)
显示 更早的评论
Hi
I hava a 3D Array. Now I like to save the content of the 3d array in n 2d arrays
2dArray = zeros(size(3dArray([1],:,:)));
for z = 1: size(3dArray(:)
2dArray(z)=3dArray(z,:,:)
end
What am I doing wrong?
0 个评论
回答(1 个)
Star Strider
2021-11-8
I am not certain what is the desired result.
Usually, the intent is to separate the ‘pages’ (third dimension) of the array into separate 2D arrays.
Likely the best option for that is —
Array3D = randi(9, 3, 4, 4);
Array3D(:,:,2) % Display Page (Dleete Later)
A3dsz = size(Array3D)
Arrays2D = mat2cell(Array3D, A3dsz(1), A3dsz(2), ones(1,A3dsz(3)));
Arrays2D{2} % Display Result
Make appropriate changes to get the desired result.
.
9 个评论
Star Strider
2021-11-8
The code in Comment overwrites ‘data_2D’ in every loop iteration. Only one (the last) 2D matrix created will result.
My code produces 3 separate matrices as cell arrays.
A small addition to it will squeeze all of them as well —
Array3D = randi(9, 3, 5, 4);
Array3D(2,:,:); % Display Page (Delete Later)
squeeze(Array3D(2,:,:)) % Display Page (Delete Later)
A3dsz = size(Array3D);
Arrays2D = mat2cell(Array3D, ones(1,A3dsz(1)), A3dsz(2), A3dsz(3));
Arrays2D{2}; % Display Result
Arrays2D = cellfun(@squeeze, Arrays2D, 'Unif',0); % Display Result
Arrays2D{2}
.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!