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 operators (<
, >
, <=
, >=
, ==
, !=
) and by the function logical()
. Because the MATLAB C++ Math Library attaches 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.
![]() | Using Logical Subscripts | Using a Logical Matrix As a One-Dimensional Index | ![]() |