# splitt a matrix in specified manner

3 views (last 30 days)
Rica on 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

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

### More Answers (1)

Jan on 10 Jul 2013
Edited: Jan on 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.