What's the difference between & and && in MATLAB?

Fantomas picture Fantomas · Sep 4, 2009 · Viewed 143.1k times · Source

What is the difference between the & and && logical operators in MATLAB?

Answer

Fraser picture Fraser · Sep 4, 2009

The single ampersand & is the logical AND operator. The double ampersand && is again a logical AND operator that employs short-circuiting behaviour. Short-circuiting just means the second operand (right hand side) is evaluated only when the result is not fully determined by the first operand (left hand side)

A & B (A and B are evaluated)

A && B (B is only evaluated if A is true)