- #1
Saladsamurai
- 3,020
- 7
OK! I am not sure how to word this, but here goes:
Let's say I want to write a conditional like:
The problem is...myVar might not ever equal exactly 4. It might be that myVar == 4.001 and that is fine; I would like it to execute the code.
Now, I know that I could give it a range like:
But is there a better way? Is there a function in MATLAB that takes my target value of 4 and my tolerance of .002 as its arguments? Or any other better ways?
Thanks!
Let's say I want to write a conditional like:
Code:
for i = 1:100
if myVar(i) == 4
do some stuff
break
end
The problem is...myVar might not ever equal exactly 4. It might be that myVar == 4.001 and that is fine; I would like it to execute the code.
Now, I know that I could give it a range like:
Code:
for i = 1:100
if myVar(i) < 4.002 && myVar(i) > 3.998
do some stuff
break
end
But is there a better way? Is there a function in MATLAB that takes my target value of 4 and my tolerance of .002 as its arguments? Or any other better ways?
Thanks!