function d = ddist(dd,x,y) n = length(x); d = 0; for i=1:n d = d + dd(x(i),y(i)); end return