MATLAB Function Reference
  Go to function:
    Search    Help Desk 
shiftdim    Examples   See Also

Shift dimensions

Syntax

Description

B = shiftdim(X,n) shifts the dimensions of X by n. When n is positive, shiftdim shifts the dimensions to the left and wraps the n leading dimensions to the end. When n is negative, shiftdim shifts the dimensions to the right and pads with singletons.

[B,nshifts] = shiftdim(X) returns the array B with the same number of elements as X but with any leading singleton dimensions removed. A singleton dimension is any dimension for which size(A,dim) = 1. nshifts is the number of dimensions that are removed.

If X is a scalar, shiftdim has no effect.

Examples

The shiftdim command is handy for creating functions that, like sum or diff, work along the first nonsingleton dimension.

See Also

reshape     Reshape array

squeeze     Remove singleton dimensions



[ Previous | Help Desk | Next ]