Reputation: 107
How do you go about adding a value to the last column of a matrix.
For example if I have a 3x3 matrix where all the values are 1. How do i select and add 3 to the third column such that the last column has values of 3 instead of 1.
Regards, Jerry
Upvotes: 2
Views: 321
Reputation: 2114
Simply use the accessor for matrix to get the vector you want to modify (i.e. last column vector) and create the vector you want to put in:
mat(:, 3) = [1; 2; 3];
And in your case you want to fill the vector with a single value, you can use:
mat(:, 3) = 3*ones(1, 3);
or
mat(:, 3) = 3;
Upvotes: 2