title: Determine if matrix A is subset of matrix B
body: <p>For a matrix such as</p>
  
  <pre><code>A = [...
      12 34 67;
      90 78 15;
      10 71 24];
  </code></pre>
  
  <p>how could we determine efficiently if it is subset of a larger matrix?</p>
  
  <pre><code>B = [...
      12 34 67;                        % found
      89 67 45;
      90 78 15;                        % found  
      10 71 24;                        % found, so A is subset of B. 
      54 34 11];
  </code></pre>
  
  <p>Here are conditions:</p>
  
  <ul>
  <li>all numbers are integers</li>
  <li>matrices are so large, i.e., <strong>row#</strong> > 100000, <strong>column#</strong> may vary from 1 to 10 (same for A and B).</li>
  </ul>
  
  <p><strong>Edit:</strong>
  It seems that <code>ismember</code> for the case of this question, when called only few times works just fine. My initial impression was due to previous experiences where <code>ismember</code> was being invoked many times inside a nested loop resulting in the worst performance.</p>
  
  <pre><code>clear all; clc
  n = 200000;
  k = 10;
  B = randi(n,n,k);
  f = randperm(n);
  A = B(f(1:1000),:);
  tic
  assert(sum(ismember(A,B,'rows')) == size(A,1));
  toc
  tic
  assert(all(any(all(bsxfun(@eq,B,permute(A,[3,2,1])),2),1))); %user2999345
  toc
  </code></pre>
  
  <p>which results in:</p>
  
  <pre><code>Elapsed time is 1.088552 seconds.
  Elapsed time is 12.154969 seconds.
  </code></pre>
  
  <p>Here are more benchmarks:</p>
  
  <pre><code>clear all; clc
  n = 20000;
  f = randperm(n);
  k = 10;
  t1 = 0;
  t2 = 0;
  t3 = 0;
  for i=1:7
      B = randi(n,n,k);
      A = B(f(1:n/10),:);
      %A(100,2) = 0;                                      % to make A not submat of B
      tic
      b = sum(ismember(A,B,'rows')) == size(A,1);
      t1 = t1+toc;
      assert(b);
      tic
      b = ismember_mex(A,sortrows(B));
      t2 = t2+toc;
      assert(b);
      tic
      b = issubmat(A,B);
      t3 = t3+toc;
      assert(b);
  end
  
                               George's       skm's
                  ismember | ismember_mex | issubmat
  n=20000,k=10      0.6326      0.1064      11.6899
  n=1000,k=100      0.2652      0.0155       0.0577
  n=1000,k=1000     1.1705      0.1582       0.2202
  n=1000,k=10000   13.2470      2.0033       2.6367
  *issubmat eats RAM when n or k is over 10000!
  *issubmat(A,B), A is being checked as submat of B. 
  </code></pre>