Operazioni logiche (booleane)
MATLAB® rappresenta i dati booleani utilizzando il tipo di dati logical
. Questo tipo di dati rappresenta gli stati true
e false
utilizzando rispettivamente i numeri 1
e 0
. Alcune funzioni e operatori di MATLAB restituiscono valori logici per indicare il verificarsi di una condizione. È possibile utilizzare questi valori logici per indicizzare un array o per eseguire un codice condizionale. Per maggiori informazioni, vedere come Find Array Elements That Meet a Condition.
Funzioni
& | Find logical AND |
Short-Circuit
&& | Logical AND with short-circuiting |
~ | Find logical NOT |
| | Find logical OR |
Short-Circuit
|| | Logical OR with short-circuiting |
xor | Find logical exclusive-OR |
all | Determine if all array elements are nonzero or true |
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.