www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/MergeTableswithOneVariableinCommonExample.m
%% Merge Tables with One Variable in Common %% % Create a table, |A|. A = table([5;12;23;2;6],... {'cereal';'pizza';'salmon';'cookies';'pizza'},... 'VariableNames',{'Age','FavoriteFood'},... 'RowNames',{'Amy','Bobby','Holly','Harry','Sally'}) %% % Create a table, |B|, with one variable in common with |A|. B = table({'cereal';'cookies';'pizza';'salmon';'cake'},... [110;160;140;367;243],... {'B';'D';'B-';'A';'C-'},... 'VariableNames',{'FavoriteFood','Calories','NutritionGrade'}) %% % Create a new table, |C|, with data from tables |A| and |B|. Use |FavoriteFood| % as a key variable to the |join| function. C = join(A,B) %% % Table |C| does not include information from the last row of table |B| % about |'cake'| since there is no corresponding entry in table |A|.