%
% La funcion DBS2=balakris(X) calcula la matriz de distancias
% de Balakrishnan-Sanghvi de una matriz de datos X (n,p)
%
function DBS2=balakris(X)
[n,p]=size(X);
DBS2=zeros(n);
Y=zeros(1,p);
for i=1:n
   for j=1:i-1
      ind=find(X(i,:)+X(j,:)==0);
      cind=find(X(i,:)+X(j,:)~=0);
      Y(cind)=(X(i,cind)-X(j,cind))./sqrt(X(i,cind)+X(j,cind));
      Y(ind)=0;
      DBS2(i,j)=2*Y*Y';
   end
end
DBS2=DBS2+DBS2';