A & BA | B~A
&, |, and ~ are the logical operators AND, OR, and NOT. They work element-wise on matrices, with 0 representing FALSE and anything nonzero representing TRUE. A & B does a logical AND, A | B does a logical OR, and ~A complements the elements of A. The function xor(A,B) implements the exclusive OR operation.
The logical operators have the lowest precedence, with arithmetic operators and relational operators being higher.Inputs AND OR XOR0 0 0 0 00 1 0 1 11 0 0 1 11 1 1 1 0
The precedence for the logical operators with respect to each other is:
They evaluate to 1 and 0 respectively, and are equivalent to:1 & 0 + 33 > 4 & 1
Here are two examples that illustrate the precedence of the logical operators to each other:1 & (0 + 3)(3 > 4) & 1
1 | 0 & 0 = 00 & 0 | 1 = 1
<,<=,>,>=,==,~=,all,any,find,xor
(c) Copyright 1994 by The MathWorks, Inc.