Skip to content

rot90

Rotate a matrix 90 degrees counter-clockwise.

B = rot90(A)
B = rot90(A, k)

Rotates A by 90° counter-clockwise. With the optional integer k, rotates by k * 90° (negative k rotates clockwise). Equivalent to applying flipud(A') for k=1, flipud(fliplr(A)) for k=2, etc.

rot90([1 2; 3 4]) % [2 4; 1 3]
rot90([1 2; 3 4], 2) % [4 3; 2 1]
rot90([1 2; 3 4], -1) % [3 1; 4 2]
  • fliplr — Flip an array left-to-right (reverse columns).
  • flipud — Flip an array upside down (reverse rows).
  • circshift — Circularly shift elements of an array.
  • permute — Rearrange dimensions of an N-D array.