%% Union of Two Vectors 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 and B.

A = [5 7 1]; 
B = [3 1 1];
[C,ia,ib] = union(A,B,'stable')

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

A = [5 7 1]; 
B = [3 1 1];
[C,ia,ib] = union(A,B,'sorted')

% Copyright 2012 The MathWorks, Inc.