How to reshape this matrix?

1 Ansicht (letzte 30 Tage)
endeavour90
endeavour90 am 6 Apr. 2012
Currently I have 3 dimensional matrix of size (2,3,3)
A(:,:,1) =
1 2 3
4 5 6
A(:,:,2) =
7 8 9
10 11 12
A(:,:,3) =
13 14 15
16 17 18
I would like to reshape it into [6 3] matrix so that it will become
A =
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17 18
I try to use reshape(A,[6 3]); But it return the wrong matrix
Is there any quick way to do this?

Akzeptierte Antwort

Gautam Vallabha
Gautam Vallabha am 6 Apr. 2012
Test matrix
A = rand(2,3,3);
Solution #1
D = reshape(permute(A, [1 3 2]), [6 3])
Solution #2
B = mat2cell(A, 2, 3, [1 1 1]); % slice into 3 cells (along dim 3)
C = squeeze(B); % flatten from dim 3 to dim 1
D = vertcat(C{:}); % vertically append the three matrices

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by