Skip to content

permute

Rearrange dimensions of an N-D array.

B = permute(A, order)

Returns A with its dimensions permuted according to order. order is a vector containing the integers 1 through ndims(A), each appearing exactly once. permute(A, [2 1]) is the transpose for 2D matrices; permute(A, [3 1 2]) cycles the dimensions of a 3D array.

A = reshape(1:24, [2 3 4]);
B = permute(A, [3 2 1]); % size [4 3 2]
ipermute(B, [3 2 1]) % round-trip back to A
  • ipermute — Inverse permute — undo a permute operation.
  • reshape — Reshape an array without changing its data.
  • squeeze — Remove singleton dimensions.