Left Join tables in MATLAB

Viewed 2736

I tried to find something relevant but to no avail, except this post which I can't say it was helpful.

I have two tables A and B: A has dimensions 5x5 and non unique values in the LastName

LastName = {'Smith';'Johnson';'Williams';'Smith';'Williams'};
YearNow= [2010;2010;2010;2010;2010];
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124; 109; 125; 117; 122];
A = table(LastName,YearNow,Height,Weight,BloodPressure);

and B has dimensions 3x2 and unique values in LastName

LastName = {'Smith';'Johnson';'Williams'};
YearBorn= [1950;1975;1965];
B = table(LastName,YearBorn);

I want to create a new column on Table A that will contain their age after I subtract for each A.YearNow the B.YearBorn, so the last column will have the form

A.Age = [60,35,45,60,45];

When I try to use [detect,pos] = ismember(A,B(:,1)); I get an error:

A and B must contain the same variables.

Any help would be appreciated.

2 Answers
Related