I want to change the individual elements in a matrix by different values simultaneously. How do I do that?
For example: I want to change the first element in matrix A by certain amount and the second element by a different amount simultaneously.
{ A = [1; 2]
% instead of doing A(1) = ..... A(2) = .....
}
You can access the elements of a vector or matrix and replace them.
For a vector this is intuitive.
This can be done for a matrix as well. The elements of a matrix are arranged in a column-first manner. You can use a single index to access the elements of a matrix.
The 2nd element of A is the same as A(2, 1). The 4th element of A is the same as A(1, 2).
So, you can set all the odd elements of A to 0 in one go like this: