How can I add column to a table based on data values in other table ?

2 views (last 30 days)
Consider the following table schemas: T1 = {'A' 'B' 'C' 'D' 'E'}; T2 = {'G' 'B' 'C' 'D'};
Given that {'B' 'C' 'D'} is the composite primary key for both T1 and T2, I want to add column 'E' to T2 from T1, that is for all records(rows) where (T1.A == T2.A AND T1.B == T2.B AND T1.C == T2.C), E_T2 = T1.E;
E_T2 will be finally added as a variable to T2.
Please help me find a solution to this.
Thanks!

Answers (1)

KL
KL on 25 Apr 2017
Edited: KL on 25 Apr 2017
A = (1:5)';
B = (1:5)';
C = (6:10)';
T1 = table(A,B,C);
T2 = table(A,B);
if(isequal(T1.A,T2.A) && isequal(T1.B,T2.B))
C_T2 = table(T1.C);
end
T2 = [T2 C_T2]
Check this out.

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!