Reputation: 541
I have a 3D matrix with the dimensions 6, 2, and 10. I want the row dimension to switch places with the height dimension, that is, 10-2-6. reshape doesn't achieve this the way I want.
How can this be done? Can I rotate the matrix?
Upvotes: 12
Views: 12497
Reputation: 34601
I think you're looking for permute
. For your case it's, permute(A,[3 2 1]);
. Here's a description of permute
from the documentation:
B = permute(A,order)
rearranges the dimensions of A so that they are in the order specified by the vector order. B has the same values of A but the order of the subscripts needed to access any particular element is rearranged as specified by order. All the elements of order must be unique.the elements of order must be unique.
It's similar to transposing a 2D matrix.
Upvotes: 17