Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Logical Operations

True or false (Boolean) conditions

The logical data type represents true or false states using the numbers 1 and 0, respectively. Certain MATLAB® functions and operators return logical values to indicate fulfillment of a condition. You can use those logical values to index into an array or execute conditional code. For more information, see how to Find Array Elements That Meet a Condition.

Functions

Logical Operators: Short-circuitLogical operations with short-circuiting
andFind logical AND
notFind logical NOT
orFind logical OR
xorFind logical exclusive-OR
allDetermine if all array elements are nonzero or true
anyDetermine if any array elements are nonzero
falseLogical 0 (false)
findFind indices and values of nonzero elements
islogicalDetermine if input is logical array
logicalConvert numeric values to logicals
trueLogical 1 (true)

Examples and How To

Find Array Elements That Meet a Condition

You can filter the elements of an array by applying one or more conditions to the array. Use relational operators (>, <, >=, <=, ==, ~=) to impose conditions on the array. Connect multiple conditions with the logical operators (&, |, ~).

Determine if Arrays Are Logical

To determine whether an array is logical, you can test the entire array or each element individually.

Reduce Logical Arrays to Single Value

Use the any or all functions to reduce an entire numeric or logical array to a single scalar logical .

Concepts

Operator Precedence

Precedence rules determine the order in which MATLAB evaluates an expression.

Truth Table for Logical Operations

This reference table shows the results of applying the binary logical operators to a series of logical 1 (true) and logical 0 (false) scalar pairs.

Was this topic helpful?