フィルターのクリア

NOT logical operators???

35 ビュー (過去 30 日間)
Natalia Wong
Natalia Wong 2016 年 1 月 31 日
編集済み: Stephen23 2016 年 1 月 31 日
Pls help I dont understand the last line when i typed it in matlab
when A = [ 1 2 3 ]
A>2 is 0 0 1
but ~A is 0 0 0
I don't get the last part. shouldn't it be 1 1 0??? and if i put ~~ it is still 0 0 0.
what does this mean??
Thanks

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 1 月 31 日
It means you tested two different things. In the first one you tested (A>2) . In the second one you tested ~A, which is the same thing as ~(A~=0) which is the same thing as (A==0)
If you wanted the negation of (A>2) then you would use ~(A>2)
  3 件のコメント
Walter Roberson
Walter Roberson 2016 年 1 月 31 日
I would suggest to you that what you typed in was
~A>2
The ~ operator has higher priority than the > operator, so that would be evaluated as
(~A)>2
and ~A is the same as (A~=0)
so ~A>2 is the same as (A~=0)>2
The result of (A~=0) is always 0 (false) or 1 (true), and neither 0 nor 1 are >2, so no matter what the input is, ~A>2 is always going to be false (or an error for other reasons.)
You need ~(A>2)
Stephen23
Stephen23 2016 年 1 月 31 日
編集済み: Stephen23 2016 年 1 月 31 日
And the reason why this is so is explained here:
which clearly shows that logical negation has a higher precedence than the relational operators. This is why Walter Roberson's answer is correct.

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

カテゴリ

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