title: Compare two vectors of unequal lengths to get a logical array
body: <p>I need to vectorize the following code:</p>
  
  <pre><code>a = [1 2 3 2 3 1];
  b = [1 2 3];
  
  for i = 1:length(a)
      for j = 1:length(b)
          r(i, j) = (a(i) == b(j));
      end
  end
  </code></pre>
  
  <p>The output r should be a logical array:</p>
  
  <pre><code> 1     0     0
   0     1     0
   0     0     1
   0     1     0
   0     0     1
   1     0     0
  </code></pre>
  
  <p>The closest I can get is:</p>
  
  <pre><code>for j = 1:length(b)
      r(:, j) = (a == b(j));
  end
  </code></pre>
  
  <p>Iterating through the shorter vector is obviously more efficient as it generates fewer for iterations. The correct solution should have no for-loops whatsoever.</p>
  
  <p>Is this possible in MATLAB/Octave?</p>