This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

permute

Permute array dimensions

Syntax

B = permute(A,dimorder)

Description

example

B = permute(A,dimorder) rearranges the dimensions of an array in the order specified by the vector dimorder. For example, permute(A,[2 1]) switches the row and column dimensions of a matrix A.

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.

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 = 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×3

     2     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.

Extended Capabilities

Introduced before R2006a