and
Logical AND, the function form of the operator &.
Category: Symbolic Computations in MATLAB > Operators and Elementary Operations
Syntax
C = and(A, B)
Same as A & B.
Description
The result is true at positions where both operands are nonzero. The operands may be numbers or logicals, and the usual size compatibility applies, so a scalar is combined with every element of an array.
For if and while conditions with scalars, && is usually preferred because it short-circuits; and and & always evaluate both sides.
Input arguments
A, B- Numeric or logical arrays with compatible sizes. Nonzero means true.
Output arguments
C- Logical array: true where both inputs are nonzero.
Example
Elementwise AND
and([1 0 1], [1 1 0])
and(true, false)
x = 1:6;
x(and(x > 2, x < 5))
Output
ans = 1×3 logical array
1 0 0
ans = logical
0
ans = 1×2
3 4
Notes
Symbolic operands are not supported (and(x > 1, x < 3) raises an error), and and takes exactly two arguments in MatLivre; three or more raise an error.