title: Optimize MATLAB code (nested for loop to compute similarity matrix)
body: <p>I am computing a similarity matrix based on Euclidean distance in MATLAB. My code is as follows:</p>
  
  <pre><code>for i=1:N % M,N is the size of the matrix x for whose elements I am computing similarity matrix
   for j=1:N
    D(i,j) = sqrt(sum(x(:,i)-x(:,j)).^2)); % D is the similarity matrix
   end
  end
  </code></pre>
  
  <p>Can any help with optimizing this = reducing the for loops as my matrix <code>x</code> is of dimension <code>256x30000</code>.</p>
  
  <p>Thanks a lot!</p>
  
  <p>--Aditya</p>