3-dimensional array
조회 수: 9 (최근 30일)
이전 댓글 표시
Example a=[1 0;0 1] b=[2 2;2 2] c=[0 3;3 0] d=cat(3,a,b,c) ==> d(:,:,1)=a ; d(:,:,2)=b; d(:,:,3)=c.
I have n-dimensional arrays are the same size, I want to merge into a 3-dimensional array. I have known about the "cat" function to concatenates into 3-dimensional array such as example , but not understand much about how to use it to solve my problem
댓글 수: 2
답변 (1개)
Leepakshi
2025년 3월 5일
Hi Yen,
To merge multiple n-dimensional arrays of identical size into a single 3-dimensional array, the cat function in MATLAB can be utilized. This function concatenates arrays along a specified dimension.
For example, given 2D arrays a, b, and c, the command cat(3, a, b, c) will concatenate these arrays along the third dimension, resulting in a 3D array. Each slice of the 3D array corresponds to one of the original arrays.
% Define the 2D arrays
a = [1 0; 0 1];
b = [2 2; 2 2];
c = [0 3; 3 0];
% Concatenate them into a 3D array
d = cat(3, a, b, c);
% Display the result
disp('d(:,:,1) =');
disp(d(:,:,1));
disp('d(:,:,2) =');
disp(d(:,:,2));
disp('d(:,:,3) =');
disp(d(:,:,3));
Please refer to below documentation on the cat function for more clarity:
Hope this helps!
댓글 수: 1
Stephen23
2025년 3월 5일
편집: Stephen23
2025년 3월 5일
"To merge multiple n-dimensional arrays of identical size into a single 3-dimensional array, the cat function in MATLAB can be utilized."
Not in general, CAT can't be utilized alone for this purpose. Here is a simple counter-example with three "n-dimensional arrays of identical size" and the output is definitely not a "single 3-dimensional array":
a = rand(5,4,3,2);
b = rand(5,4,3,2);
c = rand(5,4,3,2);
d = cat(3,a,b,c);
size(d) % not a "3-dimensional array"
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!