B = shiftdim(A,n)
shifts the dimensions of an array A by n positions.
shiftdim shifts the dimensions to the left when n is
a positive integer and to the right when n is a negative integer. For
example, if A is a 2-by-3-by-4 array, then
shiftdim(A,2) returns a 4-by-2-by-3 array.
Create a 4-by-2-by-3-by-5 array. Shift the dimensions 2 positions to the left, wrapping the first 2 lengths to the last 2 dimensions.
A = rand(4,2,3,5);
B = shiftdim(A,2);
size(B)
ans = 1×4
3 5 4 2
Shift the dimensions 2 positions to the right, resulting in 2 leading dimensions of length 1. Shifting to the right does not wrap the dimension lengths.
A — Input array vector | matrix | multidimensional array
Input array, specified as a vector, matrix, or multidimensional array.
n — Number of positions integer
Number of dimension positions to shift, specified as an integer. When
n is positive, shiftdim shifts the dimensions to
the left, wrapping the leading dimensions to the end. When n is
negative, shiftdim shifts the dimensions to the right, padding
additional leading dimensions with length 1.
GPU Arrays Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
The shiftdim 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).
Distributed Arrays Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.