0

I created a consecutive number sequence as follow:

dTime = 0:0.01:5;

However when I type

k=find(dTime==3.53)

I get:

k =

   Empty matrix: 1-by-0

But k=find(dTime==3.52), produces a result. Any recommended solutions? Why does the problem arise?

Allan D
  • 41
  • 4
  • This is only part of a larger code – Allan D Jan 11 '16 at 18:30
  • Please add the tag of the language you used – mpromonet Jan 11 '16 at 18:38
  • 6
    Welcome to the land of floating-point. This is a common issue that plagues a lot of programmers. Unless you know what you're doing, using equality to search for floating-point numbers is not recommended and will give you unexpected results as you have experienced in your question. The best thing you can do to find an exact number is to search for it within a specified tolerance. Please see the duplicate post for more information on how to do this specifically. – rayryeng Jan 11 '16 at 18:50

0 Answers0