function D = dist_list(loc)

% DIST_LIST computes the vector of distinct pairwise distances
%          for a given location vector, loc.

%Written by: TONY E. SMITH 1/28/02

%INPUT: loc = vector of locations (xi,yi)

%OUTPUT: D = (dij,i,j) for each distinct (ij) pair.

n = length(loc(:,1)) ; % number of locations

%Compute pairwise distances

D = zeros(n*(n-1)/2, 3) ; %Matrix of pairwise distances

i = 1 ;

k = 1 ;  %counter for DD.

while i < n
   
   j = i + 1 ;
   
   while j <= n
      
      D(k,1) = sqrt((loc(i,1) - loc(j,1))^2 + ...
         (loc(i,2) - loc(j,2))^2);
      
      D(k,2) = i ;
      
      D(k,3) = j ;

      j = j + 1 ;
      
      k = k + 1 ;
      
   end
   
   i = i + 1 ;
   
end

