|
Element-wise logical OR operator.
Category: Language Fundamentals > Operators and Elementary Operations
Syntax
C = A | B
Returns 1 where A or B (or both) is nonzero. Same as or(A, B).
Description
| combines conditions on whole arrays: x(x < 0 | x > 10) selects the entries outside the interval [0, 10]. Both operands are always evaluated.
For scalar conditions in if and while, || is usually preferable because it skips the second test when the first is already true.
Input arguments
A, B- Logical or numeric arrays with compatible sizes. Any nonzero value counts as true.
Output arguments
C- Logical array of the size given by implicit expansion.
Example
x = [-5 3 8 15];
x < 0 | x > 10
x(x < 0 | x > 10)
[1 0 0] | [0 0 2]
Output
ans = 1×4 logical array
1 0 0 1
ans = 1×2
-5 15
ans = 1×3 logical array
1 0 1