MATLAB: How to do a right join based on multiple columns as ID

right join base on multiple columns

Dear all,
I want to join set B from the right with set A, based on the first three columns. (The values of the three columns are the ID of both sets.) Sorry, I do not know the terminology in matlab).
All the explanations I do find are expressed in terms of keys variables, variable names and it is really confusing.
Can somebody give me pls some instructions/suggestions?
Given data set A A=[1 2 3 9 8; 1 2 3 3 12; 1 4 3 11 12; 2 3 4 3 12]
and data set B: B=[2 3 4 0 0; 1 2 3 9 8; 1 3 4 1 1; 1 2 3 6 7]
The key variables in each one of these sets are for each line the first three values.
The result should be: [2 3 4 0 0 3 12; 1 2 3 9 8 9 8; 1 2 3 9 8 3 12; 1 3 4 1 1 nAn nAn; 1 2 3 6 7 5 8; 1 2 3 6 7 3 12];

Best Answer

This comes close to doing what you want:
A=[1 2 3 9 8; 1 2 3 3 12; 1 4 3 11 12; 2 3 4 3 12];
B=[2 3 4 0 0; 1 2 3 9 8; 1 3 4 1 1; 1 2 3 6 7];
Ac = mat2cell(A, ones(size(A,1),1), [3 1 1]);
Bc = mat2cell(B, ones(size(A,1),1), [3 1 1]);
TA = cell2table(Ac , 'VariableNames',{'ID','Var1','Var2'});
TB = cell2table(Bc , 'VariableNames',{'ID','Var1','Var2'});
TJ = outerjoin(TA,TB, 'MergeKeys',1, 'Keys','ID', 'LeftVariables',{'ID','Var1','Var2'}, 'RightVariables',{'ID','Var1','Var2'})
Result:
TJ =
7×5 table
ID Var1_TA Var2_TA Var1_TB Var2_TB
___________ _______ _______ _______ _______
1 2 3 9 8 9 8
1 2 3 9 8 6 7
1 2 3 3 12 9 8
1 2 3 3 12 6 7
1 3 4 NaN NaN 1 1
1 4 3 11 12 NaN NaN
2 3 4 3 12 0 0
EDIT Corrected typographical error in the explanation. Code unchanged.