splitt a matrix in specified manner

2 Ansichten (letzte 30 Tage)
Rica
Rica am 10 Jul. 2013
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

Akzeptierte Antwort

Matt J
Matt J am 10 Jul. 2013
Bearbeitet: Matt J am 10 Jul. 2013
One way, using MAT2TILES (Available Here) is,
Acell=mat2tiles(A,[inf,3]).';
B=cell2mat(Acell);

Weitere Antworten (1)

Jan
Jan am 10 Jul. 2013
Bearbeitet: Jan am 10 Jul. 2013
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.

Kategorien

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

Community Treasure Hunt

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

Start Hunting!

Translated by