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

  • Thread starter Thread starter HannahB
  • Start date Start date
  • Tags Tags
    List Mathematica
Click For Summary
Ordering a list of (x,y) coordinates in Mathematica can be achieved by using the Sort function with a custom ordering function. The suggested function compares the x values first and then the y values if the x values are equal. This method allows for maintaining the integrity of the data rows while sorting. Users can implement this approach to effectively organize their data files, which contain multiple columns. This technique is useful for anyone needing to sort coordinate data efficiently in Mathematica.
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]])
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K