How to reshape a matrix
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
For example I would like to reshape the following matrix
1 0 0 2 0 0
0 1 0 0 2 0
to
1 0 0
0 1 0
2 0 0
0 2 0
The number of horizontally stacked matrices is now 2,so the solution is easy b = [a(1:2,:); a(3:end,:)];
The question is now how to do this for n horizontally stacked matrices without using a loop? Does someone know?
Kind regards, Carlas
0 件のコメント
採用された回答
Jan
2011 年 11 月 2 日
A = [1 0 0 2 0 0; 0 1 0 0 2 0];
B = reshape(permute(reshape(A, 2, 3, 2), [1, 3, 2]), 4, 3)
その他の回答 (2 件)
Amith Kamath
2011 年 11 月 2 日
if A is the first matrix that you defined, do:
B = [A(1:2,1:3);A(1:2,4:6)] to choose the required rows and columns from A to define B.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!