How do I reorder a 3D matrix in a specific way?
16 次查看(过去 30 天)
显示 更早的评论
I have the following matrix
MeanV(:,:,1) =
1.0000 1.0000
0.8000 0.8000
0.6000 0.6000
MeanV(:,:,2) =
1.0000 5.0000
0.8000 3.0000
0.6000 2.0000
MeanV(:,:,3) =
5.0000 4.0000
3.0000 3.0000
2.0000 1.5000
However I want the matrix to be in the order:
MeanV(:,:,1) =
1.0000 5.0000
1.0000 5.0000
1.0000 4.0000
MeanV(:,:,2) =
0.8000 3.0000
0.8000 3.0000
0.8000 3.0000
MeanV(:,:,3) =
0.6000 2.0000
0.6000 2.0000
0.6000 1.5000
I have tried using the permute function, however I am unable to get the configuration I want.
Thanks
0 个评论
回答(1 个)
James Tursa
2019-4-10
There's got to be a simpler way, but here goes
p = permute(MeanV,[2 1 3]);
result = reshape(cat(3,p(:,1,:),p(:,2,:),p(:,3,:)),3,2,3);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!