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?

  • 2
    $\begingroup$ What do you mean by "rotate this matrix by 90 degrees"? $\endgroup$
    – Kuba
    Jul 18, 2013 at 6:05
  • 1
    $\begingroup$ 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. $\endgroup$
    – Jens
    Jul 18, 2013 at 6:50
  • $\begingroup$ @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. $\endgroup$ Jul 18, 2013 at 6:57
  • $\begingroup$ @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. $\endgroup$ Jul 18, 2013 at 7:13
  • $\begingroup$ 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 $\endgroup$
    – Kuba
    Jul 18, 2013 at 7:14

1 Answer 1


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 ;)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.