0
votes

if i have the matrix

s = [ 0         0.4000    0.5000    0.6000    0.9000
      0.4000         0    0.3000    0.4000    0.5000
      0.5000    0.3000         0    0.5000    0.8000
      0.6000    0.4000    0.5000         0    0.6000
      0.9000    0.5000    0.8000    0.6000         0];

and

coordinates = [1 2; 1 3; 2 4]

then i want that the values of previous coordinates equal zero. i.e s(1,2),s(2,1),s(1,3)s(3,1),s(2,4),s(4,2) equal 0 i.e i want this result

0         0         0         0.6000    0.9000
0         0         0.3000    0         0.5000
0         0.3000         0    0.5000    0.8000
0.6000    0         0.5000         0    0.6000
0.9000    0.5000    0.8000    0.6000         0` 
1

1 Answers

3
votes

This seems to be what you want. You only need to use sub2ind:

s(sub2ind(size(s), coordinates(:,1), coordinates(:,2))) = 0; %// make these entries 0
s(sub2ind(size(s), coordinates(:,2), coordinates(:,1))) = 0; %// and symmetric entries too