필터 지우기
필터 지우기

if x==2.4 not working

조회 수: 4 (최근 30일)
Nabhdeep Bansal
Nabhdeep Bansal 2014년 10월 27일
댓글: Nabhdeep Bansal 2014년 10월 27일
* **TP1=2.4;** *
for l=1:50
TP(l)=0.1*l;
if TP(l)==TP1
........................................................
This is a small part of my program. i believe the if statement is not being executed for some reason. Further, if I put it equal to an integer (i.e. TP(l)==2) then it works. I want it to work with 2.4. Please help. If whole of the program needs to be posted, please tell. Thanks. :)

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 10월 27일
편집: Azzi Abdelmalek 2014년 10월 27일
You can use some tolerance
out=0
tol=1e-5
for l=1:50
TP(l)=0.1*l;
if abs(TP(l)-2.4)<tol
out=TP(l)
end
end
  댓글 수: 1
Nabhdeep Bansal
Nabhdeep Bansal 2014년 10월 27일
It worked. Thank You Sir.

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by