www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/InnerJoinOperationofTablesandIndicestoValuesExample.m
%% Inner-Join Operation of Tables and Indices to Values %% % Create a table, |A|. A = table({'a' 'b' 'c' 'e' 'h'}',[1 2 3 11 17]',... 'VariableNames',{'Key1' 'Var1'}) %% % Create a table, |B|, with common values in the variable |Key1| between % tables |A| and |B|, but also containing rows with values of |Key1| not % present in |A|. B = table({'a' 'b' 'd' 'e'}',[4 5 6 7]',... 'VariableNames',{'Key1' 'Var2'}) %% % Use the |innerjoin| function to create a new table, |C|, with data from % tables |A| and |B|. Retain only rows whose values in the variable |Key1| % match. % % Also, return index vectors, |ia| and |ib| indicating the correspondence % between rows in |C| and rows in |A| and |B| respectively. [C,ia,ib] = innerjoin(A,B) %% % Table |C| is sorted by the values in the key variable, |Key1|, and contains % the horizontal concatenation of |A(ia,:)| and |B(ib,'Var2')| .