Find logical OR
performsa logical OR of arrays A
| B
A
and B
andreturns an array containing elements set to either logical 1 (true
)or logical 0 (false
). An element of the outputarray is set to logical 1 (true
) if either A
or B
containa nonzero element at that same array location. Otherwise, the arrayelement is set to 0.
You can chain together several logical operations,for example, A & B | C
.
The symbols |
and ||
perform different operations in MATLAB®. The element-wise OR operator described here is |
. The short-circuit OR operator is ||
.
When you use the element-wise &
and |
operators in the context of an if
or while
loop expression (and only in that context), they use short-circuiting to evaluate expressions. Otherwise, you must specify &&
or ||
to opt-in to short-circuiting behavior. See Logical Operators: Short Circuit
for more information.