%% Shift Array Dimensions
% Shift the dimensions of an array.
% Compute a 5-D array A, and remove the leading dimensions of length 1. The shiftdim function shifts 2 dimensions and returns the 3-D array B.

A = rand(1,1,3,2,4);
[B,nshifts] = shiftdim(A);
nshifts

%

size(B)

%
% Shift the dimensions of B twice to the left.

C = shiftdim(B,2);
size(C)

%
% Shift the dimensions of C once to the right.

D = shiftdim(C,-1); 
size(D)

% Copyright 2012 The MathWorks, Inc.