Solved by KFrank in post #3 
              
              
                Hi Fly! 

In practice, for reasonable values of n and d, I expect that 
pdist will do about as well as you can. 
However, the so-called computational cost of your pdist 
solution is a suboptimal O(d * n^2).  If you search on 
closest-pair problem, you will see that your problem can 
be solved in O(d…