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.
Input array, specified as a vector, matrix, or multidimensional array.
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.
If used, the input argument n must be a constant at code
generation time.
If you do not specify the input argument n, the code generator
identifies the first dimension of A that is variable size or that
has a fixed size greater than 1. If this dimension is variable size at code generation
time and is 1 at run time, a run-time error can occur.
If n is positive and the last dimension of A
is variable size at code generation time, this dimension cannot have a size of 1 at
run time.
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).
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window.
Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.