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!