| Thread Closed |
MATLAB :: tolerance question |
Share Thread | Thread Tools |
| Apr14-10, 01:09 PM | #1 |
|
|
MATLAB :: tolerance question
OK! I am not sure how to word this, but here goes:
Let's say I want to write a conditional like: Code:
for i = 1:100 if myVar(i) == 4 do some stuff break end 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 Thanks! |
| Apr14-10, 10:22 PM | #2 |
|
|
I don't see anything wrong with the way you are doing it. If you want to reduce your two conditions to one condition, you can use absolute value like this:
Code:
target = 4; % whatever target you want tol = 0.002; % whatever tolerance you want if abs(myVar(i)-target) <= tol . . . Code:
index = find(abs(myVar-target) <= tol,1) . . . Other than that, I'm not aware of a function that does what you are asking - but if it exists, its code probably looks a lot like what you've written. Hope that helped a little. |
| Thread Closed |
| Thread Tools | |
Similar Threads for: MATLAB :: tolerance question
|
||||
| Thread | Forum | Replies | ||
| Question On Tolerance | Mechanical Engineering | 0 | ||
| Tolerance Of Bearing | Mechanical Engineering | 6 | ||
| What is tolerance? | Electrical Engineering | 1 | ||
| total tolerance | Introductory Physics Homework | 1 | ||