%% Intersection with Specified Output Order
% Use the setOrder argument to specify the ordering of the values in C.
% Specify 'stable' if you want the values in C to have the same order as in A.

A = [7 1 7 7 4]; B = [7 0 4 4 0];
[C,ia,ib] = intersect(A,B,'stable')

%
% Alternatively, you can specify 'sorted' order.

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

% Copyright 2012 The MathWorks, Inc.