Matlab has three logical operators: AND(&
), OR(|
) and NOT(~
). These operators are used to evaluate the Boolean expressions.
&
operator is used for finding the logical AND of two expressions. It will return a matrix with logical 1 where both the input matrix have logical 1 otherwise a matrix with logical 0.
|
operator is used for finding the logical OR of two expressions. It will return a matrix with logical 1 where either of the input matrix have logical 1.
~
operator is used for finding the logical NOT of an expression. If the value of an element in the input matrix is zero, then after the NOT operation, that element value will be logical 1 and vice versa.
Here's an example to demonstrate how logical operators work in Matlab:
main.m253 chars27 lines
Output:
main.m278 chars20 lines
gistlibby LogSnag