B= shiftdim(A,n)shifts the dimensions of an arrayAbynpositions.shiftdimshifts the dimensions to the left whenn是一个积极的integer and to the right whennis a negative integer. For example, ifAis a 2-by-3-by-4 array, thenshiftdim(A,2)returns a 4-by-2-by-3 array.
B= shiftdim(A)returns an array with the same elements asAbut with leading dimensions of length 1 removed.
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×43 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.
n—Number of positions integer
Number of dimension positions to shift, specified as an integer. Whennis positive,shiftdimshifts the dimensions to the left, wrapping the leading dimensions to the end. Whennis negative,shiftdimshifts the dimensions to the right, padding additional leading dimensions with length 1.
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.