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

    %% Merge Tables Using Left and Right Keys  

%% 
% Create a table, |A|. 
A = table([10;4;2;3;7],[5;4;9;6;1],[10;3;8;8;4])  

%% 
% Create a table, |B|, giving |Var2| the same contents as |Var1| from table
% |A|, except for order. 
B = table([6;1;1;6;8],[2;3;4;7;10])  

%% 
% Create a new table, |C|, containing data from tables |A| and |B|. Use
% |Var1| from table |A| with |Var2| from table |B| as key variables to the
% |join| function. 
[C,ib] = join(A,B,'LeftKeys',1,'RightKeys',2) 

%%
% |C| is the horizontal concatenation of |A| and |B(ib,2)|.