islogical

Tests whether an array is of class logical.

Category: Language Fundamentals > Data Types

Syntax

tf = islogical(A)

Returns true if A is a logical array.

Description

Comparisons, true, false and functions such as isnan produce logical arrays. The numbers 0 and 1 are doubles, not logical, so islogical(1) is false even though 1 works as a condition in if.

Use logical(x) to convert; it errors on NaN.

Input arguments

A
Any value.

Output arguments

tf
Logical scalar.

Example

Logical versus numeric

islogical(true)
islogical(3 > 2)
islogical(1)
Output
ans = logical
   1
ans = logical
   1
ans = logical
   0

See also

logical isnumeric true false