splitt a matrix in specified manner

조회 수: 1 (최근 30일)
Rica
Rica 2013년 7월 10일
hi! Ho to manipulate this matrix in this manner:
A=[a11 a12 a13 a14 a15 a16.........
a21 a22 a23 a24 a25 a26........
a31.............................
................................ ]
to
B=[a11 a12 a13
a21 a22 a23
a31 a32 a33
. ..........
............
a14 a15 a16
a24 a25 a26
.............
............
a17 a18 a19
a27 a28 a29
............
............]
thank you

채택된 답변

Matt J
Matt J 2013년 7월 10일
편집: Matt J 2013년 7월 10일
One way, using MAT2TILES (Available Here) is,
Acell=mat2tiles(A,[inf,3]).';
B=cell2mat(Acell);

추가 답변 (1개)

Jan
Jan 2013년 7월 10일
편집: Jan 2013년 7월 10일
Any permutation of the elements of an array can be achieved by a sequence of:
RESHAPE -> PERMUTE -> RESHAPE
Unfortunately I cannot find the corresponding proof anymore, so please don't take this statemant as fundamental fact.
A = [11 12 13 14 15 16; ...
21 22 23 24 25 26; ...
31 32 33 34 35 36];
[s1, s2] = size(A);
B = reshape(A, s1, 3, s2 / 3);
C = permute(B, [1, 3, 2]);
D = reshape(C, s1 * 3, s2 / 3);
Unfortunately I do not have access to Matlab currently and my powers to imagine 3D spaces suffers from the temperature of 32 C. So perhaps the permutation vector might need to be permuted also...
If you operate on large arrays, the conversion to cell and back to a double array needs a lot of time. The Mat2Tiles approach looks a little bit nicer (because the work is hidden inside the subfunction), so I'd let the degree of time-criticalness (does this term exist) decide for the method.

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by