%% Intersection of Rows in Two Matrices
% Create two matrices with rows in common.

A = [2 2 2; 0 0 1; 1 2 3; 1 1 1];
B = [1 2 3; 2 2 2; 2 2 0];

%
% Find the rows common to both A and B as well as the index vectors ia and ib, such that C = A(ia,:) and C = B(ib,:).

[C,ia,ib] = intersect(A,B,'rows')

% A and B do not need to have the same number of rows, but they must have the same number of columns.
% Copyright 2012 The MathWorks, Inc.