3-dimensional array

9 visualizaciones (últimos 30 días)
yen
yen el 18 de Mayo de 2011
Editada: Stephen23 el 5 de Mzo. de 2025
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 comentarios
Andrew Newell
Andrew Newell el 18 de Mayo de 2011
Can n be greater than 3?
Oleg Komarov
Oleg Komarov el 18 de Mayo de 2011
@yen: Do you have a question?

Iniciar sesión para comentar.

Respuestas (1)

Leepakshi
Leepakshi el 5 de Mzo. de 2025
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 comentario
Stephen23
Stephen23 el 5 de Mzo. de 2025
Editada: Stephen23 el 5 de Mzo. de 2025
"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"
ans = 1×4
5 4 9 2
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by