How to Order (x,y) Coordinates in Mathematica?

  • Context: Mathematica 
  • Thread starter Thread starter HannahB
  • Start date Start date
  • Tags Tags
    List Mathematica
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 3K views
HannahB
Messages
1
Reaction score
0
Hi everyone,

Is it possible to order a list of (x,y) coordinates in Mathematica by x, then y? I currently have a number of data files in which there are 5 columns: x, y, area, circularity, radius. I would like to order the list by x and y coordinates while keeping the rows intact.

Thank you
 
Physics news on Phys.org
There is
Code:
Sort[list, p]
sorts using the ordering function [i]p[/i].

For p you could use something like
Code:
p[a_, b_] := (a[[1]] < b[[1]]) || (a[[1]] == b[[1]] && a[[2]] < b[[2]])