For example (5x5):
m = Array[x[##] &, 5 {1, 1}];
MatrixForm@m
I want to get a clockwise ordered list with the "perimeter" elements (they could be any kind of objects). In this case:
(* {x[1, 1], x[1, 2], x[1, 3], x[1, 4], x[1, 5],
x[2, 5], x[3, 5], x[4, 5], x[5, 5],
x[5, 4], x[5, 3], x[5, 2], x[5, 1],
x[4, 1], x[3, 1], x[2, 1]}*)
The (circular) list may start at any element, no requirements about that.
It can be done easily by things like:
Join @@ {m[[1, All]], m[[2 ;; -1, -1]], m[[-1, -2 ;; 1 ;; -1]], m[[-2 ;; 2 ;; -1, 1]]}
But I want nicer ways (In case of doubt, "nicer" means "more nice")
Edit, note:
The solution should work for example with
m = Array[1 &, 5 {1, 1}];
So, using DeleteDuplicates[ ]
is not straightforward.
m[[2 ;; -2, 1]]
is wrong. Run it on a 4x4 matrix. $\endgroup$