MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Test an Entire Array


Use the islogical function to test whether A is logical.

islogical(A)

ans =

1

The result is logical 1 (true).

Use the class function to display a string with the class name of A.

class(A)

ans =

logical

The result confirms that A is logical.

Test Each Array Element


Create a cell array, C, and use the 'islogical' option of the cellfun function to
identify which cells contain logical values.

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

ans =

0 0 1 1 0 1

The result is a logical array of the same size as C.

To test each element in a numeric matrix, use the arrayfun function.

arrayfun(@islogical,A)

ans =

1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1

5 The Logical Class

Free download pdf