MATLAB Function Reference |

Convert numeric values to logical

**Syntax**

**Description**

```
K = logical(A)
```

returns an array that can be used for logical indexing or logical tests.

`A(B)`

, where `B`

is a logical array, returns the values of `A`

at the indices where the real part of `B`

is nonzero. `B`

must be the same size as `A`

.

**Remarks**

Most arithmetic operations remove the logicalness from an array. For example, adding zero to a logical array removes its logical characteristic. `A = +A`

is the easiest way to convert a logical array, `A`

, to a numeric double array.

Logical arrays are also created by the relational operators (`==`

,`<`

,`>`

,`~`

, etc.) and functions like `any`

, `all`

, `isnan`

, `isinf`

, and `isfinite`

.

**Examples**

Given `A = [1 2 3; 4 5 6; 7 8 9]`

, the statement `B = logical(eye(3)) `

returns a logical array

which can be used in logical indexing that returns `A`

's diagonal elements:

However, attempting to index into `A`

using the *numeric* array `eye(3)`

results in:

**See Also**

log2 | loglog |