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

    %% 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|. Match up rows with common values in the key variable,
% |Key1|, but also retain rows whose key values don’t have a match. 
%
% 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) 

%%
% The index vectors |ia| and |ib| contain zeros to indicate the rows in
% table |C| that do not correspond to rows in tables |A| or |B|, respectively.