if expression it is not triggered

Hallo,
the expression in the if condition is not triggered, although both terms shoud be 0.8. Am i doing something wrong with the format?
many thanks for your help
width_i=18;
deltazs1=0.7;
deltazs2=0.1;
if (deltazs1+deltazs2)==(20-width_i)/2-0.2
test=1
else
test=0
end
test =
0

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2021 年 3 月 18 日

1 投票

Give some tolerance. They are not exactly the same in the world of floating-point data.
>> 1-1/3==2/3
ans =
logical
0

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2020b

タグ

質問済み:

2021 年 3 月 18 日

回答済み:

2021 年 3 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by