How to reshape 3D matrix ?
128 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
DGM
2021 年 7 月 22 日
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.
採用された回答
その他の回答 (1 件)
Chunru
2021 年 7 月 22 日
% 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 件のコメント
Chunru
2021 年 7 月 22 日
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]);
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!