05-22-2024 04:20 PM
Hello guys,
I'm trying to get the closest or equal value to an specific value that's in a 2D array
I also need to find the line number where this value is
How can i find the value and the index of the row of this value?
Solved! Go to Solution.
05-22-2024 07:05 PM
"Array Max & Min" can find the smallest difference.
Also, most of these math nodes work with N-dim arrays.
05-22-2024 10:50 PM
Form your default values, it seems obvious that you are only interested in the first column, which is sorted.
This you can use "threshold array" as follows. (This is extremely efficient because it uses a binary search):
05-23-2024 01:28 AM - edited 05-23-2024 01:34 AM
@altenbach wrote:
This you can use "threshold array" as follows. (This is extremely efficient because it uses a binary search):
Slightly off-topic, but to be honest — I don't think it uses binary search under the hood of the Thr 1D:
Look like "brute force" linear search for me:
That was a reason why we replaced Threshold 1D with BS and got some performance improvements in Interpolate Pixel Topic.
05-23-2024 02:47 AM
I guess you are right. The solutions are not equivalent because non-descending can mean that there are duplicates. For example if we have an array [1,2,2,2,2,2,2,2,2,2,2,2,2,2,3] and look for 2, the result would be very different. Still, that can be fixed with a bit more code. 😄
(On another side note, your binary search looks way too orange... 😄 I don't have LabVIEW on my current computer so I cannot test at the moment)
05-23-2024 02:54 AM - edited 05-23-2024 03:06 AM
@Andrey_Dmitriev wrote:
@altenbach wrote:
This you can use "threshold array" as follows. (This is extremely efficient because it uses a binary search):
Slightly off-topic, but to be honest — I don't think it uses binary search under the hood of the Thr 1D:
I think you're right, because the 1D array isn't guaranteed (or required IIRC) to be ordered. Interpolate 1D Array will return the 1st found index >= "fractional index of x".
Now there's a 'sorted array' thing going on, a Interpolate Sorted 1D Array makes even more sense.
EDIT (AGAIN): That crossed...
05-23-2024 03:30 AM - edited 05-23-2024 03:32 AM
@altenbach wrote:
your binary search looks way too orange... 😄
For me it looks more "sunny" rather than a cold blue color.
Originally, it was mostly based on integer arithmetic, but the message above I've seen Input Array and a search item that are both doubles, so I quickly changed it accordingly to avoid coercion dots (and didn't check for special cases). The only algorithm's time complexity was in scope.
It could be improved, for sure, no doubt.
05-23-2024 09:57 AM
wiebe@CARYA wrote:
I think you're right, because the 1D array isn't guaranteed (or required IIRC) to be ordered.
The help says "non-descending"., but I don't understand the 2D part: Must be some math lingo.... 😄
QUOTE: "Interpolates points in a 1D array that represents a 2D non-descending graph."
05-23-2024 12:02 PM
@Andrey_Dmitriev wrote:
@altenbach wrote:
your binary search looks way too orange... 😄
Originally, it was mostly based on integer arithmetic, but the message above I've seen Input Array and a search item that are both doubles, so I quickly changed it accordingly to avoid coercion dots (and didn't check for special cases).
Indices and data never mix (until after the while loop!)
05-23-2024 12:24 PM
@altenbach wrote:
@Andrey_Dmitriev wrote:
@altenbach wrote:
your binary search looks way too orange... 😄
Originally, it was mostly based on integer arithmetic, but the message above I've seen Input Array and a search item that are both doubles, so I quickly changed it accordingly to avoid coercion dots (and didn't check for special cases).
Indices and data never mix (until after the while loop!)
Ah, constants are occasionally touched. It happens sometimes, no problem. Thank you for the notice.