cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
rverma
Level III

How do I find Euclidean distance of each point from the rest of the points in a group?

Hello,

I have a table below. I want to find the distance of each index point from the rest of the index points in the same group formed by combination of Label1 & Label2. For each group (like U1,S1) there are three index points in the table below. I need to calculate distance of point 1 from 2 & 3, 2 from 1 & 3 and 3 from 1 & 2 using X,Y coordinates. Similarly distance should be calculated of each point from the rest of points within the group for other groups as well like (U1,S2), (U2,S1) and (U2,S2). Redundant distance in the same group can be removed like distance of point 1 from 2 is same as 2 from 1.

My original table has several Label1 (U1,U2,...,U10) and Label2 (S1,S2,...S10). How can I write a jump script (jsl) that reads a table like below and create a column of distances in the same table or a new table. Ultimately I am trying to find the 50 nearest neighbors for each index point within the same group (Un,Sn)

I will greatly appreciate any guidance. Thanks.

 

jmp_question.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How do I find Euclidean distance of each point from the rest of the points in a group?

Checkout KDTable from Scripting Index to get started

Names Default To Here(1);
tbl = KDTable([1 2, 3 4, 5 6]);
distance = tbl << Distance between rows(1, 2);
//distance from row 1 to row 2 is: 
Show(distance);
{rows, dist} = tbl << K nearest rows(2);
Show(rows, dist);

or Distance:

Names Default To Here(1);
exX1 = [1 2, 3 4, 5 6];
/*Compute squared Euclidean distance*/
exD = Distance(exX1, exX1);
//sqrt(exD);
-Jarmo

View solution in original post

1 REPLY 1
jthi
Super User

Re: How do I find Euclidean distance of each point from the rest of the points in a group?

Checkout KDTable from Scripting Index to get started

Names Default To Here(1);
tbl = KDTable([1 2, 3 4, 5 6]);
distance = tbl << Distance between rows(1, 2);
//distance from row 1 to row 2 is: 
Show(distance);
{rows, dist} = tbl << K nearest rows(2);
Show(rows, dist);

or Distance:

Names Default To Here(1);
exX1 = [1 2, 3 4, 5 6];
/*Compute squared Euclidean distance*/
exD = Distance(exX1, exX1);
//sqrt(exD);
-Jarmo