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

回答(1 个)

James Tursa
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);

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by