WEIRD PROBLEM: cannot find 28.88 in an array
1 view (last 30 days)
Show older comments
E = 14:0.01:141;
find(E==28.88);
Please run the code above. The result is 'empty'? It's odd. Is this a bug in Matlab or my problem?
0 Comments
Accepted Answer
Star Strider
on 2 Sep 2015
It’s neither a bug nor your problem. It’s a combination of the inexact representation of decimal numbers as binary floating-point numbers, and the way MATLAB calculates colon-operator-generated vectors. So you have to allow for tolerances.
This works:
E = 14:0.01:141;
idx1 = find(E<=28.88, 1, 'last');
idx2 = find(E>=28.88, 1, 'first');
Result = E([idx1 idx2])
Result =
28.8700 28.8800
0 Comments
More Answers (0)
See Also
Categories
Find more on Digital Filter Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!