LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Filter nearest data on array

Solved!
Go to solution

Hello

I have the array followed with these values and I need to filter these values by comparing the id value

In this case, I need to find the values closest to 1499 and the indices of these values (In this case they are 1500... 1554). In my application, all of these input values are dynamic, they are not fixed at these values.

leandrofeder_0-1726743608306.png


Could you help me to do that?

0 Kudos
Message 1 of 5
(251 Views)

Hi Leandro,

 


@leandrofeder wrote:

I need to find the values closest to 1499 and the indices of these values (In this case they are 1500... 1554).


There is only one value "closest" to 1499 and that is 1500… (Well, maybe there could be 2 values closest to target with the same distance, unless there could be more then one array element with the same value.)

Maybe you should start with defining your problem in a more accurate way?

 


@leandrofeder wrote:

In my application, all of these input values are dynamic, they are not fixed at these values.

Could you help me to do that?


Yes: use conditional output tunnels in your loop to keep only the values/indices of interest!

 

Other suggestion: instead of strings you should work with integer data. Atleast you could convert from string to numeric value once before the loop…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(242 Views)

It's just that all the data I'm receiving comes from a string, the previous treatment I didn't put here because it's not necessary.

I adopted the conversion suggestion before the loop.

But basically my application searches for data from a place and returns an array with several numbers, these numbers must be subsequent to 1499 (in this case), then I would have to filter the array and search only 1500, 1550, 1551, 1552, 1553, 1554. Which are the closest values to 1499 compared to the rest of the array

0 Kudos
Message 3 of 5
(222 Views)
Solution
Accepted by topic author leandrofeder

A small change to your code will get you what you need

Example.png

Tim
GHSP
0 Kudos
Message 4 of 5
(219 Views)
Solution
Accepted by topic author leandrofeder

@leandrofeder wrote:

leandrofeder_0-1726743608306.png


I just want to point out why this will never work: you have the min and max reversed.

 

As it is, the range is >=1599 and <1500. That won't work: no number is smaller than 1500 and larger or equal than 1599.

 

The coercion will work, but the in range output will always be false! 

 

The range needs to be reversed.

 

I highly recommend you convert the strings to numbers as soon as possible. It's absolutely horrible to keep all data as strings, just because they came from a query or file or listbox, ring, etc..

 

Being able to see integers as integers, doubles as doubles, etc. will help you a lot in the long run.

0 Kudos
Message 5 of 5
(202 Views)