Logical (Boolean) Operations
True or false conditions
MATLAB®represents Boolean data using thelogical
data type. This data type representstrue
andfalse
states using the numbers1
and0
, respectively. Certain MATLAB functions and operators return logical values to indicate fulfillment of a condition. You can use those logical values to index into an array or execute conditional code. For more information, see how toFind Array Elements That Meet a Condition.
Funzioni
Short-circuit &&, || |
Logical operations with short-circuiting |
& |
找到逻辑, |
~ |
Find logical NOT |
| |
Find logical OR |
xor |
Find logical exclusive-OR |
all |
Determine if all array elements are nonzero ortrue |
any |
Determine if any array elements are nonzero |
false |
Logical 0 (false) |
find |
Find indices and values of nonzero elements |
islogical |
Determine if input is logical array |
logical |
Convert numeric values to logicals |
true |
Logical 1 (true) |
Argomenti
- Find Array Elements That Meet a Condition
This example shows how to filter the elements of an array by applying conditions to the array.
- Reduce Logical Arrays to Single Value
This example shows how to use the
any
andall
functions to reduce an entire array to a single logical value. - Operator Precedence
Precedence rules determine the order in which MATLAB evaluates an expression.