Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
2  
What do you mean by "rotate this matrix by 90 degrees"? –  Kuba Jul 18 '13 at 6:05
1  
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 '13 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. –  Intemediocre Jul 18 '13 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. –  Intemediocre Jul 18 '13 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 '13 at 7:14
show 4 more comments

1 Answer

up vote 3 down vote accepted

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

share|improve this answer
    
Thanks - for some reason, this transformation is happening with halirutan's answer to my question: mathematica.stackexchange.com/questions/28746/… –  Intemediocre Jul 18 '13 at 7:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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