Download MATLAB C Math Library 2.0 User's Guide
Transcript
Using mlfIndexRef( ) for Logical Indexing Using mlfIndexRef( ) for Logical Indexing This section describes how to use: • A logical index as a one-dimensional subscript • Two logical vectors as indices in a two-dimensional subscript • A colon index and a logical vector as a two-dimensional subscript • A logical index to select elements from a row or column 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’’ on page 5-16 explains the conventions used in the examples. 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. 5-31