Update table from columns of another table

Hello everyone,
I have two tables, “Atab” and “Btab”, and I would like to update “Atab” by adding all the columns (variables) and their respective values that are in “Btab” but not in “Atab” (meaning columns “Trans” and “Det”).
See in attached “Atab”, “Btab” and the expected “Output” in jpeg files.
Thanks in advance

 Accepted Answer

Avars = A.Properties.VariableNames;
Bvars = B.Properties.VariableNames;
BnotA = setdiff(Bvars, Avars);
Atab = [Atab, B(:,BnotA)];

3 Comments

Hello Walter, thanks for your help.
By implementing your code, in the last line MATLAB gives the following error:
All tables being horizontally concatenated must have the same number of rows.
Why is that?
Thanks again
Yes I would like to innerjoy, but based on the example in the link, I would like that “T” shows as well rows “1” with “Var2” empty and rows “7” and “9” with “Var1” empty.

Sign in to comment.

More Answers (0)

Asked:

on 21 Dec 2021

Commented:

on 21 Dec 2021

Community Treasure Hunt

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

Start Hunting!