title: Matlab - euclidean distance of specific elements between two vectors
body: <p>I'm trying to find the coordinates/index that has the minimum distance of an element in a 2d array to another same element 2d array. I have a binary image from my edge detection problem and a ground truth image. For example, I have A as my binary image  and B as the ground truth image:</p>
  
  <pre><code>A = [0 255 255 255;255 255 255 255;255 255 255 255;255 255 255 255 ]
  
  B = [255 255 255 255;255 255 255 255; 255 255 0 255; 255 255 0 0]
  </code></pre>
  
  <p>0 is black and 255 is white. My algorithm goes like this:</p>
  
  <pre><code> for n=1:maxindex
  if(A(n)==0&amp;&amp;B(n)==0)
  distance(n) = 0;
  
  elseif(A(n)==0&amp;&amp;B(n)==255)
  for m=1: maxindex
       if(B(m)==0&amp;&amp;m~=n)
          translate index to subscripts
          compute euclidean distance
          store value in temporary vector
      end
   end
  find minimum in temporary vector
  distance(n) = minimum found
  </code></pre>
  
  <p>end
  end</p>
  
  <p>The algorithm really takes a long time for large images, since it's exhaustive when there's a mismatch. Is there a function in Matlab that would make this faster?</p>