LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Strange behaviour when comparing array values

Solved!
Go to solution

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?

 

 

Problem.png

 

Thanks!

 

 

--
Smarter than the average bear!
0 Kudos
Message 1 of 4
(3,564 Views)
Solution
Accepted by topic author Vince84

This is expected behavior. You have to learn about correct floating point number comparison.

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 2 of 4
(3,556 Views)

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!

--
Smarter than the average bear!
0 Kudos
Message 3 of 4
(3,532 Views)

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:

--
Smarter than the average bear!
Message 4 of 4
(3,522 Views)