Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

rot90

Rotate array 90 degrees

Syntax

Description

example

B = rot90(A) rotates array A counterclockwise by 90 degrees. For multidimensional arrays, rot90 rotates in the plane formed by the first and second dimensions.

example

B = rot90(A,k) rotates array A counterclockwise by k*90 degrees, where k is an integer.

Examples

collapse all

Rotate Column Vector

Create a column vector of sequential elements.

A = (1:5)'
A =

     1
     2
     3
     4
     5

Rotate A counterclockwise by 90 degrees using rot90.

B = rot90(A)
B =

     1     2     3     4     5

The result, B, has the same elements as A but a different orientation.

Rotate Multidimensional Array

Create a 3-by-3-by-2 cell array of strings.

A = cat(3,{'a' 'b' 'c';'d' 'e' 'f';'g' 'h' 'i'},{'j' 'k' 'l';'m' 'n' 'o';'p' 'q' 'r'})
A(:,:,1) = 

    'a'    'b'    'c'
    'd'    'e'    'f'
    'g'    'h'    'i'


A(:,:,2) = 

    'j'    'k'    'l'
    'm'    'n'    'o'
    'p'    'q'    'r'

Rotate the cell array by 270 degrees.

B = rot90(A,3)
B(:,:,1) = 

    'g'    'd'    'a'
    'h'    'e'    'b'
    'i'    'f'    'c'


B(:,:,2) = 

    'p'    'm'    'j'
    'q'    'n'    'k'
    'r'    'o'    'l'

The function rotates each page of the array independently. Since a full 360 degree rotation (k = 4) leaves the array unchanged, rot90(A,3) is equivalent to rot90(A,-1).

Input Arguments

collapse all

A — Input arrayvector | matrix | array | cell array | categorical array

Input array, specified as a vector, matrix, array, cell array, or categorical array of any data type.

Complex Number Support: Yes

k — Rotation constantinteger

Rotation constant, specified as an integer. Specify k to rotate by k*90 degrees rather than nesting calls to rot90.

Example: rot90(A,-2) rotates A by -180 degrees and is equivalent to rot90(A,2), which rotates by 180 degrees.

More About

collapse all

Tips

  • Use the flip function to flip arrays in any dimension.

See Also

| |

Introduced before R2006a

Was this topic helpful?