function dist=distance(d,c) %DIST Distance from hub dist=distance(d,c) % This finds the square of the distance between each point and its hub % d = data coordinates of points; c = cluster array contains index of % hub to which point is assigned; c(i)=j point i belongs to the cluster % whose hub is point j n = size(d,1); for i = 1:n dif(i,:)= d(c(i),:) - d(i,:); end dist =( sum((dif.*dif)'))'; %sums the squares of the row elements end