cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
SG
SG
Level III

Absolute value between all points

I was wondering if there is an easy way to aggregate the absolute value of all points in a column to one another. I have written some scripts which will give me the stage location data for a tool, but I want to see how the locations measure up relative to themselves rather than the absolute locations of the machine.

 

For example:

If I have 3 points, I want to know the distance between 1-2, 1-3, and 2-3.

If I have 4 points, I want to know the distance between 1-2, 1-3, 1-4, 2-3, 2-4, and 3-4.

And so on...

 

For small data sets this can easily be done, but I have data sets ranging from 20-100 points. I am looking for something built in or possibly an idea to script the solution. Any help is much appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp
Level X

Re: Absolute value between all points

I guess that 'easier' depends on what else your code does, and how. But if you want teh matrix to be lower triangular you could use:

Names Default To Here( 1 );
// Data
v = [1, 2, 3, 4];
// Compute Euclidean distance between all pairs of points
dm = Sqrt(Distance(v, v));
// Make matrix dm lower triangular
dm2 = J(NRow(dm), NCol(dm), .);
for (r=1, r<=NRow(dm), r++,
	dm2[r, 1::r] = dm[r, 1::r];
);
dt = AsTable(dm2);

View solution in original post

6 REPLIES 6
txnelson
Super User

Re: Absolute value between all points

I think this might do what you want:

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\big class.jmp" );
a = dt:weight << get values;
b = a;
c = [];
For( i = 1, i <= N Rows( a ), i++,
	c = c || abs( a[i] - b);
	dt << New Column( "col" || Char( i ), values( c[0, i] ) );
);
Jim
ian_jmp
Level X

Re: Absolute value between all points

You might also use the 'Distance()' function (see 'Help > Scripting Guide'):

Names Default To Here( 1 );
// Data
v = [1, 2, 3, 4];
// Compute Euclidean distance between all pairs of points
dm = Sqrt(Distance(v, v));
dt = AsTable(dm);
txnelson
Super User

Re: Absolute value between all points

Nice

Jim
SG
SG
Level III

Re: Absolute value between all points

Awesome solutions! Both work really well for what I'm doing. I like the 'Distance()' function, I'll have to look into it more.

 

I have a follow up question:
Both these solutions essentially produce a matrix with the distance between each point in the cell. I was wondering if there is an easy way to remove either the lower or upper triangle of the matrix? I don't need both sides and it will make analysis easier.

ian_jmp
Level X

Re: Absolute value between all points

I guess that 'easier' depends on what else your code does, and how. But if you want teh matrix to be lower triangular you could use:

Names Default To Here( 1 );
// Data
v = [1, 2, 3, 4];
// Compute Euclidean distance between all pairs of points
dm = Sqrt(Distance(v, v));
// Make matrix dm lower triangular
dm2 = J(NRow(dm), NCol(dm), .);
for (r=1, r<=NRow(dm), r++,
	dm2[r, 1::r] = dm[r, 1::r];
);
dt = AsTable(dm2);
SG
SG
Level III

Re: Absolute value between all points

Perfect! Thank you, this was indeed easy for my application.

 

I have a python script running that extracts and then reads the location data from an XML file into a CSV. Then I am using JMP to analyze the stage locations from the CSV. So, I don't have any other jsl for what I'm trying to do...yet.