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.
B = rot90([A](#bt6yu8i-1-A),[k](#bt6yu8i-1-k))
rotates array A
counterclockwise by k*90
degrees, where k
is an integer.
Examples
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
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
- Use the flip function to flip arrays in any dimension.
- When visualizing rotated data, the coordinate system used for plotting can impact the appearance of the rotation. For example, plotting rotated data
B
using the commandimagesc(B)
followed by the commandaxis xy
to automatically choose the_x_ and y axes can cause the data to appear as though it was rotated clockwise instead of counterclockwise.
Extended Capabilities
Usage notes and limitations:
- Does not support cell arrays for the first argument.
Usage notes and limitations:
- Does not support cell arrays for the first argument.
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