MATLAB Answers

0

How do I reorder a 3D matrix in a specific way?

Asked by Isaac Brambley on 10 Apr 2019
Latest activity Answered by James Tursa
on 10 Apr 2019
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 Comments

Sign in to comment.

Products


Release

R2017b

1 Answer

Answer by James Tursa
on 10 Apr 2019

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 Comments

Sign in to comment.