Skip to content

circshift

Circularly shift elements of an array.

B = circshift(A, shiftsize)

Cycles the elements of A by shiftsize positions. shiftsize is either a scalar (shift along the first non-singleton dimension) or a vector (one shift per dimension). Positive values shift forward (toward higher indices); negative values shift backward. Elements wrapped past the boundary reappear at the opposite end.

circshift([1 2 3 4 5], 2) % [4 5 1 2 3]
circshift([1 2 3 4 5], -1) % [2 3 4 5 1]
circshift(magic(4), [1 2]) % shift down 1, right 2
  • fliplr — Flip an array left-to-right (reverse columns).
  • flipud — Flip an array upside down (reverse rows).
  • rot90 — Rotate a matrix 90 degrees counter-clockwise.