How to reshape 3D matrix ?
72 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
SojM
el 22 de Jul. de 2021
Comentada: SojM
el 22 de Jul. de 2021
I have a 3D matrix of 36*42*7 dimension. I want to reshape it in such a way that I extract two colums from each third dimension. That means my final matrix dimension would be 7*2*756. How can I do this?
For example, Assume I have 4*4*3 matrix
A1= [a b c d; e f g h; i j k l; m n o p]
A2= [q r s t; u v w x; y z A B; C D E F]
A3= [G H I J; K L M N; O P Q R; S T U V ]
Now I want to reshape it to 3*2*8 such that
B1= [a b; q r; G H]
B2=[c d; s t; I J]
B3=[e f; u v; K L]
B4..... B8
2 comentarios
DGM
el 22 de Jul. de 2021
Your question is ambiguous. There are a number of ways 10584 elements can be reshaped from one array to another with the same number of elements. If one assumes that everything should be columnwise, then you can just use reshape()
A = rand(36,42,7);
B = reshape(A,7,2,756);
size(B)
Otherwise, you'll have to explain how you want the data to be oriented.
Respuesta aceptada
Stephen23
el 22 de Jul. de 2021
A = randi(9,4,4,3)
B = permute(reshape(permute(A,[2,1,3]),[2,8,3]),[3,1,2])
3 comentarios
Stephen23
el 22 de Jul. de 2021
"How can it be done for large matrix of 36*42*7 to reshpae it into 7*2*756 in a simlar way?"
B = permute(reshape(permute(A,[2,1,3]),[2,756,7]),[3,1,2])
% ^ ^^^ ^
Más respuestas (1)
Chunru
el 22 de Jul. de 2021
% Generate data (using number 1,...48 to represent a,...V)
Z = permute(reshape(1:48, [4 4 3]), [2 1 3])
% First permute the dimension so that a,b,c,.. are along the 1st dim
Z1 = permute(Z, [2 1 3])
% No reshape
Z2 = reshape(Z1, [2 8 3])
% permute
Z3 = permute(Z2, [3 1 2])
3 comentarios
Chunru
el 22 de Jul. de 2021
Exactly same:
Z = rand(36, 42, 7);
Z1 = permute(Z, [2 1 3]);
Z2 = reshape(Z1, [2 756 7]); %2x756 = 36*42
Z3 = permute(Z2, [3 1 2]);
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!