shiftdim
Shift dimensions.
Syntax
y = shiftdim(x,n)
[y,ns] = shiftdim(x)
Inputs
- x
 - The matrix or string whose elements are to be shifted.
 - n
 - The number of shifts made to the dimensions of x.
 
Outputs
- y
 - The shifted result.
 - ns
 - The number of leading dimensions removed when n is omitted.
 
Examples
Shift to the left:
y = shiftdim(reshape([1:24],[2,3,4]), 2)
      y = 
slice(:, :, 1) = 
[Matrix] 4 x 2
 1   2
 7   8
13  14
19  20
slice(:, :, 2) = 
[Matrix] 4 x 2
 3   4
 9  10
15  16
21  22
slice(:, :, 3) = 
[Matrix] 4 x 2
 5   6
11  12
17  18
23  24
      Shift to the right:
y = shiftdim([1,2,3,4,5]',-1)
      y = [Matrix] 1 x 5
1  2  3  4  5