Using the C++ Math Library    

Assigning to a Multiple Elements

Use a vector index to modify multiple elements in a matrix.

The colon() index frequently appears in the subscript of the destination because it allows you to modify an entire row or column. For example, the code

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:

You can also use a logical index to select multiple elements. For example, the assignment statement

changes all the elements in A that are greater than 5 to 17:


 Assigning to a Single Element Assigning to a Subarray