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

    %% Union of Two Tables and Their Indices  

%% 
% Define a table, |A|, of gender, age, and height for three people. 
A = table(['M';'M';'F'],[27;52;31],[74;68;64],...
'VariableNames',{'Gender' 'Age' 'Height'},...
'RowNames',{'Ted' 'Fred' 'Betty'})  

%% 
% Define a table, |B| with the same variables as |A|. 
B = table(['F';'M'],[64;68],[31;47],...
'VariableNames',{'Gender' 'Height' 'Age'},...
'RowNames',{'Meg' 'Joe'})  

%% 
% Find the union of tables |A| and |B|, as well as the index vectors, |ia|
% and |ib|. 
[C,ia,ib] = union(A,B) 

%%
% The data for |Meg| and |Betty| are the same. |union| only returns the
% index from |A|, which corresponds to |Betty|.