rot90 - Rotate array 90 degrees - MATLAB (original) (raw)

Syntax

Description

B = rot90([A](#bt6yu8i-1-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](#bt6yu8i-1-A),[k](#bt6yu8i-1-k)) rotates array A counterclockwise by k*90 degrees, where k is an integer.

example

Examples

collapse all

Create a column vector of sequential elements.

Rotate A counterclockwise by 90 degrees using rot90.

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

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

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

A = 3×3×2 cell array 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 = 3×3×2 cell array 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

Input array, specified as a vector, matrix, or multidimensional array.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | cell | categorical | datetime | duration | calendarDuration
Complex Number Support: Yes

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.

Tips

Extended Capabilities

expand all

Usage notes and limitations:

Usage notes and limitations:

The rot90 function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Version History

Introduced before R2006a