Suppose I have an NxN matrix A, an index vector V consisting of a subset of the numbers 1:N, and a value K, and I want to do this:
for i = V A(i,i) = K end Is there a way to do this in one statement w/ vectorization?
e.g. A(something) = K
The statement A(V,V) = K will not work, it assigns off-diagonal elements, and this is not what I want. e.g.:
>> A = zeros(5); >> V = [1 3 4]; >> A(V,V) = 1 A = 1 0 1 1 0 0 0 0 0 0 1 0 1 1 0 1 0 1 1 0 0 0 0 0 0