Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Absolute value between all points

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 27, 2017 2:48 PM
(2583 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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);
```

6 REPLIES 6

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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);
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Absolute value between all points

Nice

Jim

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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);
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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.