title: mutual distance between each 2 points in 3D
body: <pre><code>rv=[rx ry rz];   %# [N-by-3] rx , ry , rz are [N-by-1]
  
  for i=1:N
      for j=1:N
          dx(i,j)=rv(i,1)-rv(j,1);    %# dx is x component of distance between each 2 points [N-by-N]
          dy(i,j)=rv(i,2)-rv(j,2);
          dz(i,j)=rv(i,3)-rv(j,3);
      end
  end
  d=cat(3,dx,dy,dz);
  </code></pre>
  
  <p>Is there a faster method to construct <strong>d</strong> ?</p>
  
  <p>Thanks a lot for any guide.</p>
  
  <p>Edit:</p>
  
  <pre><code>N= 997 
  Me:               Elapsed time is 17.271125 seconds.
  DiggyF:           Elapsed time is 0.241841 seconds.
  Oli Charlesworth: Elapsed time is 0.120425 seconds.
  N=1986 
  DiggyF          : Elapsed time is 1.183639 seconds.
  Oli Charlesworth: Elapsed time is 0.502964 seconds.
  </code></pre>