Community Tip - You can change your system assigned username to something more personal in your community settings. X

Translate the entire conversation x

Find Nearest number in a table.

EP_10996709
8-Gravel

Find Nearest number in a table.

ok.  something you just need to reach out to the power users.  

 

I'm working in Prime 8 and have a simple spread sheet.  not knowing all the available size if I enter a number, I should get the nearest available number to pull data.    This should be simple right.  

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:EP_10996709)

The last row number should be 19, not 20.

 

If we can assume that the values in the “size” column are sorted in ascending order, this expression should deliver the desired result.

Werner_E_0-1738918437339.png

 

The result of match always is a vector, even if it contains just one element. Therefore we have to use the vector index 0 (=ORIGIN) to get the row value itself. This value is then used in the row operator to extract the desired data row. I found that easier than extracting every value one by one from its data vector (Size, OD, Max, Tol).

 

The modifier "near" will find 2,75 when the input is 2.8 and 3 if the input is 2.99.

Don't know what you will use it for, but sometimes its necessary to choose the nearest value which is less than or equal to the input value (so 2.99 should yield 2.75) or to choose the nearest value which is greater or equal to the input (so 2.8 would yield 3). Her you would use the modifiers "leq" and "geq".

 

I turned the calculation into a small utility function which also shows how to deal with "leq" (you can't simply chose the first element in the vector of indices but must reverse that vector first).

Werner_E_1-1738918981489.png

 

Again the function assumes the values in the first column to be in ascending order.

If they are not, you could add  table <-- csort(table,O)  on top of the program, but if you do so, the table that is transferred must not have a header row with text but only data values, otherwise "csort" would throw an error.

 

Remark: If the input value is exactly (or within the usual tolerance) in-between two data values, the "match" function with "near" would return the indices of both and because our approach uses index 0, the lower value would be returned.

 

Don't have Prime 8 installed. You have to work from the pictures. But I attach the Prime 10 file for whatever it may be worth.

 

 

View solution in original post

3 REPLIES 3
LucMeekes
23-Emerald III
(To:EP_10996709)

You may want to use the match() function.

See the help info for its usage, especially regarding the third parameter.

 

Success!

Luc

Werner_E
25-Diamond I
(To:EP_10996709)

The last row number should be 19, not 20.

 

If we can assume that the values in the “size” column are sorted in ascending order, this expression should deliver the desired result.

Werner_E_0-1738918437339.png

 

The result of match always is a vector, even if it contains just one element. Therefore we have to use the vector index 0 (=ORIGIN) to get the row value itself. This value is then used in the row operator to extract the desired data row. I found that easier than extracting every value one by one from its data vector (Size, OD, Max, Tol).

 

The modifier "near" will find 2,75 when the input is 2.8 and 3 if the input is 2.99.

Don't know what you will use it for, but sometimes its necessary to choose the nearest value which is less than or equal to the input value (so 2.99 should yield 2.75) or to choose the nearest value which is greater or equal to the input (so 2.8 would yield 3). Her you would use the modifiers "leq" and "geq".

 

I turned the calculation into a small utility function which also shows how to deal with "leq" (you can't simply chose the first element in the vector of indices but must reverse that vector first).

Werner_E_1-1738918981489.png

 

Again the function assumes the values in the first column to be in ascending order.

If they are not, you could add  table <-- csort(table,O)  on top of the program, but if you do so, the table that is transferred must not have a header row with text but only data values, otherwise "csort" would throw an error.

 

Remark: If the input value is exactly (or within the usual tolerance) in-between two data values, the "match" function with "near" would return the indices of both and because our approach uses index 0, the lower value would be returned.

 

Don't have Prime 8 installed. You have to work from the pictures. But I attach the Prime 10 file for whatever it may be worth.

 

 

Werner. 

  Thanks so much.  I am working in both Prime 8 and 10 so checking out the file is not a problem.  There is so much I still need to learn and never enough time to get into all these different function like "leg", and "geq".  

Announcements

Top Tags