%% Inner-Join Operation of Tables and Indices to Values
% Create a table, Tleft.

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

%
% Create a table, Tright, with common values in the variable Key1 between tables Tleft and Tright, but also containing rows with values of Key1 not present in Tleft.

Tright = table({'a' 'b' 'd' 'e'}',[4 5 6 7]',...
         'VariableNames',{'Key1' 'Var2'})

%
% Use the innerjoin function to create a new table, T, with data from tables Tleft and Tright. Retain only rows whose values in the variable Key1 match.
% Also, return index vectors, ileft and iright indicating the correspondence between rows in T and rows in Tleft and Tright respectively.

[T,ileft,iright] = innerjoin(Tleft,Tright)

% Table T is sorted by the values in the key variable, Key1, and contains the horizontal concatenation of Tleft(ileft,:) and Tright(iright,'Var2').
% Copyright 2012 The MathWorks, Inc.