function d = rankdistancevsps(xall)

N = 2819;
M = size(xall,2);
for j = 1:M
  tmp = 0;
  for i = 1:N
    for k = 1:N
      if (((xall(i,j) < xall(k,j)) & (xall(i,M) > xall(k,M)))|((xall(i,j) > xall(k,j)) & (xall(i,M) < xall(k,M))))
      tmp = tmp+1;
      end;
    end;
  end;
  d(j)=tmp;
  disp(j);
end;

d = d./(N*N);
d = d + ones(1,M)*(10e-9);
