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

    %% Left Outer-Join Operation of Tables and Indices to Values  

%% 
% Create a table, |A|. 
A = table({'a' 'b' 'c' 'e' 'h'}',[1 2 3 11 17]',...
    'VariableNames',{'Key1' 'Var1'})  

%% 
% Create a table, |B|, with common values in the variable |Key1| between
% tables |A| and |B|, but also containing rows with values of |Key1| not
% present in |A|. 
B = table({'a','b','d','e'}',[4;5;6;7],...
    'VariableNames',{'Key1' 'Var2'})  

%% 
% Use the |outerjoin| function to create a new table, |C|, with data from
% tables |A| and |B|. Ignore rows in |B| whose key values do not match any
% rows in |A|. 
%
% Also, return index vectors, |ia| and |ib| indicating the correspondence
% between rows in |C| and rows in |A| and |B| respectively. 
[C,ia,ib] = outerjoin(A,B,'Type','left') 

%%
% All values of |ia| are nonzero indicating that all rows in |C| have corresponding
% rows in |A|.