フィルターのクリア

two value difference is not complete 0. how can make it complete 0?

1 回表示 (過去 30 日間)
Sarfaraz Ahmed
Sarfaraz Ahmed 2018 年 11 月 12 日
コメント済み: Sarfaraz Ahmed 2018 年 11 月 12 日
Hi, I am using eq function to see the difference but when i get these two values it's not giving right answer. fo example : when I get a=0.164, b=0.164 then output of eq function should be 1 but it produce 0. can anyone please help in this problem ? Thanks
function y = op(a,b)
x= eq(a,b);
if (x ~=0)
out=0;
else
out=1;
end
y = out;

採用された回答

KSSV
KSSV 2018 年 11 月 12 日
編集済み: KSSV 2018 年 11 月 12 日
You cannot compare floating numbers using ==. You need to set a tolerance and check for the difference and come to decision.
a=0.164 ;
b=0.164 ;
tol = 10^-5 ;
if abs(a-b)<= tol
disp('They are equal')
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by