PDA

View Full Version : Ordering a list in Mathematica


HannahB
Jan4-12, 08:58 AM
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

CompuChip
Jan4-12, 09:48 AM
There is

Sort[list, p]
sorts using the ordering function p.


For p you could use something like

p[a_, b_] := (a[[1]] < b[[1]]) || (a[[1]] == b[[1]] && a[[2]] < b[[2]])