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

    %% Difference of Two Tables and Indices to Different Rows  

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

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

%% 
% Find the rows in |A| that are not in |B|, as well as the index vector
% |ia|, such that |C = A(ia,:)|. 
[C,ia] = setdiff(A,B) 

%%
% The rows of |C| are in sorted order first by |Gender| and next by |Age|.