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 Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by