splitt a matrix in specified manner
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
更多回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!