Documentation

permute

Permute array dimensions

Description

example

B = permute(A,dimorder)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 matrixA.

Examples

collapse all

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.

rngdefaultA = 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 = permute(a,[3 2 1])
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
szB = size(B)
szB =1×32 4 3

Input Arguments

collapse all

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.

Compatibility Considerations

expand all

Behavior changed in R2019b

Extended Capabilities

Introduced before R2006a