title: pdist2 equivalent in MATLAB version 7
body: <p>I need to calculate the euclidean distance between 2 matrices in matlab. Currently I am using bsxfun and calculating the distance as below( i am attaching a snippet of the code ):</p>
  
  <pre><code>for i=1:4754
  test_data=fea_test(i,:);
  d=sqrt(sum(bsxfun(@minus, test_data, fea_train).^2, 2));
  end
  </code></pre>
  
  <p>Size of fea_test is 4754x1024 and fea_train is 6800x1024 , using his for loop is causing the execution of the for to take approximately 12 minutes which I think is too high. 
  Is there a way to calculate the euclidean distance between both the matrices faster?</p>
  
  <p>I was told that by removing unnecessary for loops I can reduce the execution time. I also know that pdist2 can help reduce the time for calculation but since I am using version 7. of matlab I do not have the pdist2 function. Upgrade is not an option.</p>
  
  <p>Any help. </p>
  
  <p>Regards,</p>
  
  <p>Bhavya </p>