Using the C Math Library | ![]() ![]() |
Using One Colon Index and One Logical Vector as Indices
This type of indexing is very similar to the two-vector case. Here, however, the colon index selects all of the elements in a row or column, acting like a vector of ones the same size as the dimension to which it is applied. The logical index works just like a nonlogical index in terms of size.
For example, let the index vector B = logical([1 0 1])
. Then
mlfIndexRef(A, "(?,?)", mlfCreateColonIndex(), B)
1 7 2 8 3 9
The colon index selects all rows, and B
selects the first and third columns in each row. The result is the intersection of these two sets, that is, the first and third columns of the matrix.
mlfAssign(&X, mlfIndexRef(A, "(?,?)", B, mlfCreateColonIndex()));
1 4 7 3 6 9
B
selects the first and third rows, and the colon index selects all the columns in each row. The result is the intersection of the sets selected by each index, that is, the first and third rows of the matrix.
![]() | Using Two Logical Vectors as Indices | Using a Scalar and a Logical Vector | ![]() |