OK! I am not sure how to word this, but here goes:(adsbygoogle = window.adsbygoogle || []).push({});

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.Code (Text):

for i = 1:100

if myVar(i) == 4

do some stuff

break

end

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?Code (Text):

for i = 1:100

if myVar(i) < 4.002 && myVar(i) > 3.998

do some stuff

break

end

Thanks!

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# MATLAB tolerance question

Loading...

Similar Threads - MATLAB tolerance question | Date |
---|---|

Matlab Coding angular spectrum of waves in a fluid | Yesterday at 7:30 AM |

How to program this in Matlab | Feb 28, 2018 |

Matlab Making a short test for self-adjointness | Feb 23, 2018 |

Mathematica Question about updating functions | Oct 23, 2017 |

**Physics Forums - The Fusion of Science and Community**