Using the C Math Library | ![]() ![]() |
Assigning to Multiple Elements
Use a vector index to modify multiple elements in a matrix.
A colon index frequently appears in the subscript of the destination because it allows you to modify an entire row or column. For example, this code
mlfIndexAssign(&A, "(?,?)", mlfScalar(2), mlfCreateColonIndex(), mlfColon(mlfScalar(1),mlfScalar(3),NULL));
replaces the second row of an M-by-3 matrix with the vector 1 2 3
. If we use the example matrix A
, A
is modified to contain:
1 4 7 1 2 3 3 6 9
You can also use a logical index to select multiple elements. For example, the assignment statement
mlfIndexAssign(&A, "(?)", mlfGt(A,mlfScalar(5)), mlfHorzcat(mlfScalar(17), mlfScalar(17), mlfScalar(17), mlfScalar(17),NULL));
changes all the elements in A
that are greater than 5
to 17
:
1 4 17 2 5 17 3 17 17
![]() | Assigning to a Single Element | Assigning to a Subarray | ![]() |