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
>> B=[0,4,4;4,0,4;4,4,0] B = 0 4 4 4 0 4 4 4 0 >> v=[1,2,3] v = 1 2 3 >> B(eye(size(B))==1)=v %insert values from v to eye positions in B B = 1 4 4 4 2 4 4 4 3