LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I find the element with the closest value to a calculated "target value" in a 1D array?

Hello all,

may be the following question is very simple, but I am relatively new in labview and it would be great if somebody could help me:

I have a acquaried 1D array of data-points. Now, I have to find the element in this array which value is the closest to a calculated "target value".

After finding the element with the value close to the "target value", I have to get the position of this element (i.e. the index) in the 1D array.

Now, I have to use this index to find and extract the element at this position in an other 1D array.

It would be very nice if somebody could help me with this problem.

Thank you,

beam
0 Kudos
Message 1 of 5
(3,979 Views)
Find attached a sample vi that you can modify.
Message 2 of 5
(3,979 Views)
If this array is sorted in ascending order you can use 'threshold 1D array',
round the result to nearest integer, and index the second array.

If it is not a sorted array it gets just slightly more complicated. You can
subtract your target value from the array you are searching, do an absolute
value and then use 'Array max & min'. The minimum value output is the
smallest delta between the values in the array and your target value, so
take the 'min index' output (from that function) and use that to index your
other array.
Message 3 of 5
(3,979 Views)
Thank you very much for you help. It works and is exactly what I need!
0 Kudos
Message 4 of 5
(3,979 Views)
Thank you very much for your suggestions. They helped to solve the problem!
0 Kudos
Message 5 of 5
(3,979 Views)