www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/UnionofTwoVectorswithSpecifiedOutputOrderExample.m

    %% 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')