Integrating tolerance level with MATLAB gt(A,B)

Hello!
Is there any good way to use gt(A,B) to determine if A>B with a tolerance level, as in ismembertol(A,B) to determine equality?
Best regards, Nils

Answers (2)

A = 1;
B = 1.2;
tol = 0.25;
strictlyGreater = A > B
greaterWithTolerance = A > (B - tol)

6 Comments

Thank you for your reply!
It doesn't really work properly though.
I have two arrays with 8760 values each, let's say A and B, and a tolerance of 1e-4.
When I try: x = sum( A > (B - tol));
I still get too many values. Any suggestion why?
Impossible to say without seeing a SMALL (not all 8760 values) sample of data that show the problem. Show that data, state what you expect the result to be, and state what you actually see.
Relative tolerance or absolute?
So a small sample:
A = [219 219 219 219]; B = [219 219 214.9524 174.8961];
Since the values in B are calculated floating values, the A(1) and A(2) have decimals up to 18 decimals, and strict "<" doesn't do the trick.
Thanks again!
For this example, turn on hex formatting and display A and B. That way we can regenerate the EXACT values of your A and B variables.
format hex
A
B
format % restore default formatting
For those exact A and B vectors, what would you want the output of this to be?
tf = greaterThanWithTolerance(A, B)
If you would expect to call such a function with a user-specified tolerance, what tolerance would you expect to specify to receive your desired output?
tf = greaterThanWithTolerance(A, B, tol)
What shows up for
fprintf('%.999g\n', B-A)
?
Also please clarify whether you would like the tolerance to be absolute or relative.

Sign in to comment.

No, there is no good way to use gt() for this purpose: overriding the gt method of double class runs too much risk of breaking things. For example it could break max()

Categories

Asked:

on 19 Apr 2017

Commented:

on 21 Apr 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!