function D = dist_pairwise(L1,L2)

%DIST_PAIRWISE computes the matrix, D, of pairwise distances 
%between two sets of locations, L1 and L2.

%Written by: TONY E. SMITH, 2/10/98
%
%INPUTS: L1 = (n1 x 2)-matrix of locations, L1(i,:) = (X1i,Y1i)
%        L2 = (n2 x 2)-matrix of locations, L2(i,:) = (X2i,Y2i)
%
%OUTPUTS: D = (n1 x n2)-matrix of pairwise distances
                 

n1 = size(L1,1);
n2 = size(L2,1);  %numbers of locations


% Start procedure.

X1 = L1(:,1) ; 

X2 = L2(:,1);

Y1 = L1(:,2) ; 

Y2 = L2(:,2);

U1 = ones(n1,1); 

U2 = ones(n2,1);

XX = X1*U2' - U1*X2' ;

YY = Y1*U2' - U1*Y2' ;

D = sqrt(XX.^2 + YY.^2) ;


