Message Boards Message Boards

1
|
7421 Views
|
6 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Wolfram Language equivalent to Matlab Rot90?

Posted 8 years ago

Does anyone know if there is there a wolfram equivalent for the Matlab command Rot90 ?

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.


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

POSTED BY: Paul Davidson
6 Replies
Posted 8 years ago

Thank you evryone for your comments but special thanks to Sander for such a simple solution.

POSTED BY: Paul Davidson

Other possibilities are:

rotcw2 = Reverse/*Transpose;
rotccw2 = Transpose/*Reverse;

rotcw3[x_]:=Transpose[Reverse[x]]
rotccw3[x_]:= Reverse[Transpose[x]]

rotcw4 = Transpose[Reverse[#]]&
rotccw4 = Reverse[Transpose[#]]&

rotcw5 = (Reverse /@ Transpose[#])&
rotccw5 = (Transpose[Reverse /@ #])&

Or using Table:

Table[a[[dimx - j + 1, i]], {i, dimy}, {j, dimx}] // MatrixForm   
Table[a[[j, dimy - i + 1]], {i, dimy}, {j, dimx}] // MatrixForm    

You can probably also use SparseArray or MapIndexed... There are many many ways of doing this, it just depends on what you feel most comfortable using... @* or /* or /@ or #...& might seem intimidating for some people...

POSTED BY: Sander Huisman

As David said it is very easy to do so:

rotccw = Reverse@*Transpose; (* defines a function to do counterclockwise rotation *)
rotcw = Transpose@*Reverse;  (* and clockwise rotation *)

a = Partition[Range[16], 4];
MatrixForm[a]
MatrixForm[rotcw[a]]
MatrixForm[rotccw[a]]
POSTED BY: Sander Huisman
Posted 8 years ago

Also, have a look at Transpose and Reverse. Note that Mathematica represents matrices and tensors as list structures.

POSTED BY: David Keith

For Graphics look up Rotate, and for vectors look up RotationTransform or RotationMatrix.

This is not what the OP asks for. Rot90 'rotates' a matrix in 90 degree steps (http://fr.mathworks.com/help/matlab/ref/rot90.html). Not rotation like Rotate, RotationTransform, RotationMatrix.

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract