1
 tfinal = 10;
 dt_fine = 0.0000001;
 tvec_fine = [0:dt_fine:tfinal];
 find(tvec_fine==0.1)


ans =
Empty matrix: 1-by-0

Why does the above code not find the index where tvec_fine has the entry 0.1. It clearly has the entry based on the definition of tvec_fine.

GameOfThrows
  • 4,510
  • 2
  • 27
  • 44
  • 3
    aha, floating point precision - https://stackoverflow.com/questions/686439/why-is-24-0000-not-equal-to-24-0000-in-matlab – GameOfThrows May 04 '17 at 14:56

1 Answers1

0

This is because floating point has a narrow precision, and 0.1 could end up being 0.10000001 vs 0.1000000002 for example.

This is a very rough description just to give you an idea, as pointed in the comments more developed answers and solutions are already available on SO.

Stack Player
  • 1,470
  • 2
  • 18
  • 32