Issue with find() function
Mostra commenti meno recenti
If I create an array x = 0.1:0.05:0.6; and then ask find(x==0.15), I get an empty matrix. It also fails for x==0.40? I don't understand this at all.
1 Commento
Cedric
il 5 Giu 2014
If you understand the answers below, read about EPS. In the end, you will probably end up doing something like:
pos = find( abs(x - 0.15) < eps(1) ) ;
Risposta accettata
Più risposte (2)
Image Analyst
il 5 Giu 2014
Here's some pretty general code based on the FAQ Azzi referred you to:
x = 0.1 : 0.05 : 0.6 % Sample data
targetValue = 0.15 % Whatever value you want to find
tolerance = .005 % We want to find x within this value of the target.
% Find values in range.
indexesInRange = abs(x - targetValue) <= tolerance
xThatAreInRange = x(indexesInRange)
% Or, in an if statement, if you want to use it in an if statement instead...
if abs(x(2) - targetValue) <= tolerance
% x(2) is close enough to the targetValue.
else
% x(2) is far away from the targetValue.
end
Categorie
Scopri di più su Mathematics in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!