Using the C++ Math Library | ![]() ![]() |
Assigning to a Subarray
Use two vector indices to generate a matrix destination. For example, let the vector index B
equal 1 2
, and the vector index C
equal 2 3
. Then,
A(B,C) = vertcat(horzcat(1, 4) horzcat(3, 2));
copies a 2-by-2 matrix into the second and third columns of rows 1 and 2: the upper right corner of A
. The example matrix A
becomes:
1 1 4 2 3 2 3 6 9
You can also use a logical matrix as an index. For example, let B
be the logical matrix:
0 1 1 0 1 1 0 0 0
A(B) = vertcat(horzcat(1, 4) horzcat(3, 2));
1 1 4 2 3 2 3 6 9
![]() | Assigning to a Multiple Elements | Assigning to All Elements | ![]() |