Using the C Math Library | ![]() ![]() |
Overview
Logical indexing is a special case of n-dimensional indexing. A logical index is a vector or a matrix that consists entirely of ones and zeros. Applying a logical subscript to a matrix selects the elements of the matrix that correspond to the nonzero elements in the subscript.
Logical indices are generated by the relational operator functions (mlfLt()
, mlfGt()
, mlfLe()
, mlfGe()
, mlfEq()
, mlfNeq()
) and by the function mlfLogical()
. Because these functions attach a logical flag to a logical matrix, you cannot create a logical index simply by assigning ones and zeros to a vector or matrix.
You can form an n-dimensional logical subscript by combining a logical index with scalar, vector, matrix, or colon indices.
The examples work with matrix A
and the logical array B
.
A 1 4 7 2 5 8 3 6 9 B 1 0 1 0 1 0 1 0 1
Assumptions for the Code Examples explains the conventions used in the examples.
![]() | Logical Indexing | Using a Logical Matrix as a One-Dimensional Index | ![]() |