%% Merge Tables Using Row Names as Keys
% Create a table, Tleft.

Tleft = table(['M';'M';'F';'F';'F'],[38;43;38;40;49],...
        'VariableNames',{'Gender' 'Age'},...
        'RowNames',{'Smith' 'Johnson' 'Williams' 'Jones' 'Brown'})

%
% Create a table, Tright, such that the rows of Tleft and the rows of Tright have a one-to-one correspondence.

Tright = table([64;69;67;71;64],...
         [119;163;133;176;131],...
         [122 80; 109 77; 117 75; 124 93; 125 83],...
         'VariableNames',{'Height' 'Weight' 'BloodPressure'},...
         'RowNames',{'Brown' 'Johnson' 'Jones' 'Smith' 'Williams'})

%
% Create a new table, T, with data from tables Tleft and Tright. Use the vectors of row names as key variables. (The name of the vector of row names of a table is 'Row', as shown by Tleft.Properties.DimensionNames{1}.)

T = join(Tleft,Tright,'Keys','Row')

% The rows of T are in the same order as Tleft.
% Copyright 2012 The MathWorks, Inc.