operators-logical

Programming

Logical operators. && (short-circuit AND), || (short-circuit OR), ~ or ! (NOT). & and | are element-wise logical AND/OR for arrays. Nonzero values are treated as true.

Syntax

a && b
a || b
~a
a & b
a | b

Examples

true && false
▶ Run
~true
▶ Run
[1, 0, 1] & [1, 1, 0]  % returns [1, 0, 0]
▶ Run

See Also

Try SimLab — Free MATLAB® Alternative

466 functions. Runs in your browser. No install.

Open SimLab

Stay Updated

Get notified about new simulations and tools. We send 1-2 emails per month.