permute - Permute array dimensions - MATLAB (original) (raw)
Syntax
Description
B = permute([A](#d126e1309127),[dimorder](#mw%5Fb1696e97-e21c-4a95-b50c-3adcb5f03239))
rearranges the dimensions of an array in the order specified by the vectordimorder
. For example, permute(A,[2 1])
switches the row and column dimensions of a matrix A
. In general, thei
th dimension of the output array is the dimensiondimorder(i)
from the input array.
Examples
Create a 3-by-4-by-2 array and permute it so that the first and third dimensions are switched, resulting in a 2-by-4-by-3 array.
rng default A = rand(3,4,2)
A = A(:,:,1) =
0.8147 0.9134 0.2785 0.9649
0.9058 0.6324 0.5469 0.1576
0.1270 0.0975 0.9575 0.9706
A(:,:,2) =
0.9572 0.1419 0.7922 0.0357
0.4854 0.4218 0.9595 0.8491
0.8003 0.9157 0.6557 0.9340
B = B(:,:,1) =
0.8147 0.9134 0.2785 0.9649
0.9572 0.1419 0.7922 0.0357
B(:,:,2) =
0.9058 0.6324 0.5469 0.1576
0.4854 0.4218 0.9595 0.8491
B(:,:,3) =
0.1270 0.0975 0.9575 0.9706
0.8003 0.9157 0.6557 0.9340
Input Arguments
Input array, specified as a vector, matrix, or multidimensional array.
Dimension order, specified as a row vector with unique, positive integer elements that represent the dimensions of the input array.
Extended Capabilities
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:
dimorder
must be a fixed-size row vector.- If
B
is a heterogeneous cell array,dimorder
must be a constant. To learn more about heterogeneous cell arrays, see Code Generation for Cell Arrays (MATLAB Coder).
The permute
function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced before R2006a
You can generate C/C++ code for this function.
Starting in R2019b, the syntax permute(A,dimorder)
produces an error when dimorder
is a noninteger or complex value. Instead, specify real, positive integer values for dimorder
.