フィルターのクリア

if condition equal many variables

1 回表示 (過去 30 日間)
AA
AA 2015 年 3 月 15 日
コメント済み: Image Analyst 2015 年 3 月 15 日
If 6==6==6
c=1
Else
c=0
end
When i type the above code i get c=0 but logically i should get c=6 As 6 is equal to 6. Where is my error and how could i rewrite the code?

採用された回答

Roger Stafford
Roger Stafford 2015 年 3 月 15 日
You should realize that "6==6==6" is operated on as:
(6==6)==6
The (6==6) will give a true result, and which in combination with the third 6 will be converted to a numerical 1. Then you have 1==6 which is false. You will always get a false result with c = 0 as a result. In other words 6==6==6 is definitely false in the matlab world. Advice: don't use it! What were you trying to achieve?
  2 件のコメント
AA
AA 2015 年 3 月 15 日
So how do i rewrite it, assume u have x,y,z=6 and u want to see if x=y=z
Image Analyst
Image Analyst 2015 年 3 月 15 日
if x == y && y == z

サインインしてコメントする。

その他の回答 (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