Using the C Math Library | ![]() ![]() |
Using a Scalar and a Logical Vector
Let matrix X
be a 4-by-4 magic square.
X = magic(4); 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
Let B
be a logical matrix that indicates which elements in row two of matrix X
are greater than 9. B
is the result of the greater than (>
) operation
mlfAssign(&target_row, mlfIndexRef(X, "(?,?)", mlfScalar(2), mlfCreateColonIndex())); mlfAssign(&B, mlfGt(target_row, mlfScalar(9)));
0 1 1 0
In MATLAB, B = (X(2,:) > 9)
performs the same operation.
Use B
as a logical index that selects those elements from matrix X
.
mlfAssign(&C, mlfIndexRef(X, "(?,?)", mlfScalar(2), B));
11 10
![]() | Using One Colon Index and One Logical Vector as Indices | Extending Logical Indexing to N Dimensions | ![]() |