How to reshape a matrix?
1 回表示 (過去 30 日間)
古いコメントを表示
Suppose I have a 2D matrix (6,3) as follows
A
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17 18
Now I want to reshape into one 3D matrix (3,3,2) like as follows:
A_3D(:, :, 1)
1 2 3
4 5 6
7 8 9
A_3D(:, :, 2)
10 11 12
13 14 15
16 17 18
How I can achieve that with an efficient way?
Thank you
採用された回答
Ameer Hamza
2020 年 10 月 2 日
編集済み: Ameer Hamza
2020 年 10 月 2 日
Combination of reshape and permute
permute(reshape(A, 3, size(A,1)/3, []), [1 3 2])
4 件のコメント
Ameer Hamza
2020 年 10 月 3 日
I am glad to be of help. You can run each part one by one and see the output. That will help in understanding.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!