Test of Approximately Equality
28 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I have a value b and c. b and c are approximatly equal (b~c). They have +-5% difference.
I want to test of approximately equality..like this:
if b~c (with +-5% difference)
return something...
end
0 件のコメント
回答 (3 件)
Jan
2012 年 6 月 17 日
You only have to decide if it should be 5% of the first or the second argument. Then:
if abs(b - c) < 0.05 * b
or
if abs(b - c) < 0.05 * max(b, c)
or
if abs(b - c) < 0.05 * min(b, c)
or
if abs(b - c) < 0.05 * (b + c) * 0.5
2 件のコメント
Greg Heath
2012 年 6 月 18 日
1. Try using "abs" on the RHS
2. Might also consider median(abs(b),abs(c))
Greg
Stephen Nagy
2017 年 12 月 29 日
Your desired goal isn't entirely clear, but depending on the outcome you seek, the functions "uniquetol" and some of its related functions might be helpful.
1 件のコメント
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!