Integrating tolerance level with MATLAB gt(A,B)

조회 수: 1 (최근 30일)
Nils Norlander
Nils Norlander 2017년 4월 19일
댓글: Walter Roberson 2017년 4월 21일
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

답변 (2개)

Steven Lord
Steven Lord 2017년 4월 19일
A = 1;
B = 1.2;
tol = 0.25;
strictlyGreater = A > B
greaterWithTolerance = A > (B - tol)
  댓글 수: 6
Steven Lord
Steven Lord 2017년 4월 21일
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)
Walter Roberson
Walter Roberson 2017년 4월 21일
What shows up for
fprintf('%.999g\n', B-A)
?
Also please clarify whether you would like the tolerance to be absolute or relative.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2017년 4월 19일
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()

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by