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!