# A rotation-like transform on a matrix

Do not be confused with comments, those are for previous version of the question - Kuba

Imagine I have a matrix of the form:

MatrixForm[{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}]


I would like to apply a transform that generates a matrix of the form:

MatrixForm[{{4, 8, 12, 16}, {3, 7, 11, 15}, {2, 6, 10, 14}, {1, 5, 9, 13}}]


What would be the appropriate terminology for this transformation? It looks a bit like a 90 degree counterclockwise rotation of the elements in the matrix.

Is there a simple way to do it in Mathematica with large matrices?

• What do you mean by "rotate this matrix by 90 degrees"?
– Kuba
Jul 18, 2013 at 6:05
• I can't relate the example to a $90^{\circ}$ rotation in any way. By some definition of "rotation," you could apply twice the transformation in this question.
– Jens
Jul 18, 2013 at 6:50
• @Jens I mean rotation in the sense that we write out the Matrix form of the expression of a surface, and rotated that surface by 90 degrees. Jul 18, 2013 at 6:57
• @sebhofer If you're thinking about a matrix of pixel values, the rotation I describe could be understood and rotating around a point at the center of the matrix. Jul 18, 2013 at 7:13
• 1) see sebhofer's comment 2) even with your interpretation it would be rather 180 not 90 degrees, but still no close since the matrix would be upside-down. 3) do not get me wrong, we want to help you but you have to know what do you want. For example Reverse@TestMatrix will do the job but is not a general solution
– Kuba
Jul 18, 2013 at 7:14

This will do the job:

t = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}
Transpose@(Reverse /@ t) // MatrixForm


It is not just ad hoc method. Reverse/@ is "reflection" in x direction (while Reverse@ in y), Transpose is "reflection" through y= -x. So this composition is not a guess.

Using this remarks it is easily to show some kind reverse approach:

Reverse@(Transpose@ t)


I used "reflection" because is not a real reflection, only positions are reflected. In our case coordinates origin is at the center of MatrixForm. I haven't said Matrix intentionally to not be confused what is center of the matrix for even dimension case.

One could show good mathematical notation in this case. I'm not experienced in dealing with groups so I will not do this ;)