if x==2.4 not working
4 ビュー (過去 30 日間)
古いコメントを表示
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. :)
0 件のコメント
採用された回答
Azzi Abdelmalek
2014 年 10 月 27 日
編集済み: Azzi Abdelmalek
2014 年 10 月 27 日
read this http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
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
その他の回答 (0 件)
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!