02-02-2017 03:23 AM - edited 02-02-2017 03:24 AM
Hi,
I am having some trouble getting the right index for a specific value in an array. The Array is the "xi used" output of the Interpolate 1D function, which is a simple ramp with steps of 0.001, no repeated numbers.
When I use the "Search 1D array" function, or a conditional for loop I get a very strange behaviour, where on some numbers it gives the right index, but others I get an error from the Search funtion or the last index from the for loop. The following snippet is a debugging tool I made to try to understand what's happening an it should have the values for the "interpolated X" variable. If you try some trigger values like (0.102, 0.211, 0.302) It wont find the index, but for other values it will. This is part of a automated system that finds a specific current valuein an I-V curve and from that index gets the Voltage value for that current.
What is happening?
Thanks!
Solved! Go to Solution.
02-02-2017 03:29 AM
This is expected behavior. You have to learn about correct floating point number comparison.
02-02-2017 04:22 AM - edited 02-02-2017 04:28 AM
Interesting. I am migrating code I created in Matlab and I am not sure how they handle this there (I assume the function has the proper algorithms for the comparison integrated) but you do can do direct comparisons.
Thanks for the answer!
02-02-2017 04:36 AM - edited 02-02-2017 04:38 AM
NI has a white paper about this. Useful for simple solutions:
http://www.ni.com/white-paper/7612/en/
This is one is more than enough for my problem: