Inverse permute array dimensions
Create a 4-by-3-by-2 array B
, and compute its inverse permutation according to the dimension order [3 1 2]
.
rng default
B = rand(4,3,2)
B = B(:,:,1) = 0.8147 0.6324 0.9575 0.9058 0.0975 0.9649 0.1270 0.2785 0.1576 0.9134 0.5469 0.9706 B(:,:,2) = 0.9572 0.4218 0.6557 0.4854 0.9157 0.0357 0.8003 0.7922 0.8491 0.1419 0.9595 0.9340
A = ipermute(B,[3 1 2])
A = A(:,:,1) = 0.8147 0.9572 0.6324 0.4218 0.9575 0.6557 A(:,:,2) = 0.9058 0.4854 0.0975 0.9157 0.9649 0.0357 A(:,:,3) = 0.1270 0.8003 0.2785 0.7922 0.1576 0.8491 A(:,:,4) = 0.9134 0.1419 0.5469 0.9595 0.9706 0.9340
The inverse permutation A
is the array such that, when you permute it using the same dimension order, the result is equal to the original array B
.
C = permute(A,[3 1 2])
C = C(:,:,1) = 0.8147 0.6324 0.9575 0.9058 0.0975 0.9649 0.1270 0.2785 0.1576 0.9134 0.5469 0.9706 C(:,:,2) = 0.9572 0.4218 0.6557 0.4854 0.9157 0.0357 0.8003 0.7922 0.8491 0.1419 0.9595 0.9340
B
— Input arrayInput array, specified as a vector, matrix, or multidimensional array.
dimorder
— Dimension orderDimension order, specified as a row vector with unique, positive integer elements representing the dimensions of the input array.
This function supports tall arrays with the limitation:
Permuting the tall dimension (dimension one) is not supported.
For more information, see Tall Arrays for Out-of-Memory Data.
Usage notes and limitations:
Does not support cell arrays for the first argument.
See Variable-Sizing Restrictions for Code Generation of Toolbox Functions (MATLAB Coder).
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
You have a modified version of this example. Do you want to open this example with your edits?