필터 지우기
필터 지우기

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 CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by