www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/KeepOneCopyofNonkeyVariablesExample.m
%% Keep One Copy of Nonkey Variables % Create a new table with data from tables |A| and |B|. If any nonkey variables % have the same name in both tables, keep only the copy from table |A|. %% % Create a table, |A|. A = table([10;4;2;3;7],[5;4;9;6;1]) %% % Create a table, |B|, giving |Var2| the same contents as |Var2| from table % |A|. B = table([6;1;1;6;8],[5;4;9;6;1],[10;3;8;8;4]) %% % Create a new table, |C|, with data from tables |A| and |B|. Use |Var2| % as a key variable to the |join| function and keep only the copy of |Var1| % from table |A|. C = join(A,B,'Keys','Var2','KeepOneCopy','Var1') %% % |C| does not contain the |Var1| data from table |B|.