2017-05-09 20 views
0

3D配列sを2D配列sReshapeに変換する必要があります。第3次元のすべてのスライスが最初のスライスの2D配列の行の下に置かれます。MATLAB:3Dを2D(連結)に変換する

s = reshape((1:30),[5,3,2]); 
sReshape = ??? 

resultExpected = [(1:5),(16:20) ; (6:10),(21:25) ; (11:15),(26:30)]'; 
isequal(sReshape, resultExpected) 

答えて

2

あなたが再形成する前に第二と第三の次元を切り替えることpermuteを使用することができます:

s = reshape((1:30),[5,3,2]); 
% switch between the 2nd and third dimensions 
y = permute(s,[1 3 2]); 
% reshape into 3 columns matrix 
sReshape = reshape(y,[],3); 

resultExpected = [(1:5),(16:20) ; (6:10),(21:25) ; (11:15),(26:30)]'; 
isequal(sReshape, resultExpected) 
+0

完璧に取り組んだということ

は、ここでは一例と同様に、予想されるソリューションです。ありがとう! – Andi

関連する問題