Accelerating the pace of engineering and science

# Documentation Center

• Trials

## Identifying Logical Arrays

### Function Summary

This table shows the commands you can use to determine whether or not an array x is logical. The last function listed, cellfun, operates on cell arrays.

Command

Operation

whos(x)

Display value and data type for x.

islogical(x)

Return true if array is logical.

isa(x, 'logical')

Return true if array is logical.

class(x)

Return string with data type name.

cellfun('islogical', x)

Check each cell array element for logical.

### Examples of Identifying Logical Arrays

Create a 3-by-6 array of logicals and use the whos function to identify the size, byte count, and class (i.e., data type) of the array.

```A = gallery('uniformdata',[3,6],0) > .5
A =

1     0     0     0     1     0
0     1     0     1     1     1
1     1     1     1     0     1

whos A
Name      Size            Bytes  Class      Attributes

A         3x6                18  logical
```

Find the class of each of these expressions:

```B = logical(-2.8);  C = false;  D = 50>40;  E = isinteger(4.9);

whos B C D E
Name      Size            Bytes  Class      Attributes

B         1x1                 1  logical
C         1x1                 1  logical
D         1x1                 1  logical
E         1x1                 1  logical              ```

Display the class of A:

```A = gallery('uniformdata',[3,6],0) > .5;
fprintf('A is a %s\n', class(A));

A is a logical```

Create cell array C and use islogical to identify the logical elements:

```C = {1, 0, true, false, pi, A};
cellfun('islogical', C)
ans =
0     0     1     1     0     1```