MATLAB: How do you find and replace rows in two tables with some variables in common

MATLABouterjoinreplacesubsettable

There are two tables. Table "A" is a subset of "B". How do you find the rows in "A" and "B" that have the same "X" and "Y" variables and replace those rows in "B" with those rows in "A"?
>> var1 = {'a', 'b', 'c' 'd' 'e'}';
>> x1 = [5 4 3 2 1]';
>> y1 = [9 8 5 4 1]';
>> var2 = {'Temp', 'Temp', 'Temp', 'Temp', 'Temp'}';
>> x2 = [1 2 3 4 5]';
>> y2 = [1 3 5 7 9]';
>> A = table(var1,x1,y1);
>> B = table(var2,x2,y2);

Best Answer

Use the "outerjoin" function to find the indices of the match.
>> [C,ia,ib] = outerjoin(A, B, 'Keys', [2:3], 'MergeKeys', true, 'Type', 'right');
"ia" and "ib" show where each of the table rows in "C", come from in tables "A" and "B". A zero in "ia" indicates that that row in table "C" does not appear in table "A". Use these indices to find the indices in tables "A" and "B" where "ia" is not zero and then find the values at those indices in "ia" and "ib".
>> inda = find(ia~=0);
>> indb = ib(inda);
Those give the correlated indices in tables "A" and "B" that need to be switched.
Then, you can use those indices to index into the "B" table and replace it with the values you obtain by indexing into the "A" table. 
>> B(indb,1)=A(ia(inda),1);