Skip to main content

list manipulation - How to rearrange the matrix elements in a special way?


This is a follow up on this question. Consider a matrix m1 as


m1 = {{1, 2, 3}, {4, 9, 5}, {6, 7, 8}};

In MatrixForm it looks like


enter image description here


I want to rearrange the elements in a way such that it looks like


enter image description here


Consider another example.


m2 = {{1, 2, 3, 4, 5}, {6, 17, 18, 19, 7}, {8, 20, 25, 21, 9}, {10, 22, 23, 24, 11}, {12, 13, 14, 15, 16}};


In MatrixForm,


enter image description here


And I want to transform this into


enter image description here


Basically, I want the boundary elements to be sorted in a counter clock-wise with the smallest element at the center-right.


How can I do this?




Comments