www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/MergeTablesUsingRowNamesasKeysExample.m
%% Merge Tables Using Row Names as Keys %% % Create a table, |A|. A = table(['M';'M';'F';'F';'F'],[38;43;38;40;49],... 'VariableNames',{'Gender' 'Age'},... 'RowNames',{'Smith' 'Johnson' 'Williams' 'Jones' 'Brown'}) %% % Create a table, |B|, such that there is a one-to-one correspondence between % the rows of |A| and the rows of |B|. B = 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, |C|, with data from tables |A| and |B|. Use the row % names as keys to the |join| function. C = join(A,B,'Keys','RowNames') %% % The rows of |C| are in the same order as |A|.