Main Content

rot90

Rotate array 90 degrees

Description

example

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

example

B = rot90(A,k)rotates arrayAcounterclockwise byk*90degrees, wherekis an integer.

Examples

collapse all

Create a column vector of sequential elements.

A = (1:5)'
A =5×11 2 3 4 5

RotateAcounterclockwise by 90 degrees usingrot90.

B = rot90(A)
B =1×51 2 3 4 5

The result,B, has the same elements asAbut 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 =3x3x2 cell arrayA(:,:,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 =3x3x2 cell arrayB(:,:,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)相当于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. Specifykto rotate byk*90degrees rather than nesting calls torot90.

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

Tips

  • Use theflipfunction to flip arrays in any dimension.

  • 当旋转数据可视化,坐标系统em used for plotting can impact the appearance of the rotation. For example, plotting rotated dataBusing the commandimagesc(B)followed by the commandaxis xyto automatically choose thexandyaxes can cause the data to appear as though it was rotated clockwise instead of counterclockwise.

Extended Capabilities

Version History

Introduced before R2006a

See Also

||