title: fast version of ismember() function in MATLAB
body: <p>My question is about finding an alternative approach to what <code>ismember()</code> does in MATLAB in a much more faster way.</p>
  
  <p>Here is my problem:</p>
  
  <pre><code>M [92786253*1]  (a: roughly 100M rows)
  x [749*1]       (b: # of rows can vary from 100 to 10K)
  </code></pre>
  
  <p>I want to find rows in <code>b</code> that co-exists in <code>a</code> (the row indices of a). <strong>This operation needs to be repeated about 10M times</strong> for different version of <code>b</code>.</p>
  
  <p><strong>The Normal Approach:</strong></p>
  
  <pre><code> tic
   ind1 = ismember(M,x);
   toc
  
   Elapsed time is 0.515627 seconds.
  </code></pre>
  
  <p><strong>The Fast Approach:</strong></p>
  
  <pre><code> tic
   n = 1;
   ind2 = find(any(all(bsxfun(@eq,reshape(x.',1,n,[]),M),2),3));
   toc
  
   Error using bsxfun
   Requested 92786253x1x749 (64.7GB) array exceeds maximum array size preference. 
   Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive.
   See array size limit or preference panel for more information.
  
   Error in demo_ismember_fast (line 23)
   ind2 = find(any(all(bsxfun(@eq,reshape(x.',1,n,[]),M),2),3))
  </code></pre>
  
  <p>The second approach is usually 15-20 times faster than the normal one, however in this case, I cannot use it for memory limitation. Are there any suggestion how to speedup this operation? Thanks for sharing expert opinions with me!</p>