02-13-2015 07:38 AM
Hello,
i have a double-array A and a double value B.
How can i find out which number in the array A is the nearest number to the number B?
Thanks for help
Solved! Go to Solution.
02-13-2015 08:02 AM
There's a few different ways to do this. The most efficient will depend on the properties of array A.
Is array A sorted? If so, I think a threshold and final compare will be your best bet.
If not, you can brute force it by calculating a distance array and taking the min value from there.
02-13-2015 08:05 AM
The array-size is only 10 values.
How do i calculate a distance -array?
02-13-2015 08:09 AM
I guess I'd do this as a distance squared array.
distance squared array = (A-B)^2
Then do a Min-Max on the distance squared array to find the index of minimum distance. That index on your A array is the closest numeric value to B.
With just 10 values, your other alternative would be to sort A, then do a threshold of A using B to find the transition index. Compare either side to find the minimum.
02-13-2015 08:15 AM
You aren't giving many details, or answering the questions already asked. But still I think this is easy enough. As mentioned if the arrays are sorted you can probably optimize it.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
02-13-2015 08:26 AM
Thanks you for trhe example.
My B is only a value, not array. Only A is an array.
02-13-2015 08:31 AM - edited 02-13-2015 08:31 AM
Hi One,
you already have more than 700 messages in the forum so I guess you already left the "absolute beginner" status (regarding LabVIEW) behind you.
But still you are not able to calculate the minimal difference of an array and a scalar number?
02-17-2015 01:23 PM
If the array is sorted, the built in function "Threshold 1D Array" might work for you.