MATLAB: How to replace items in a table with items from another table after comparison

replacetable

I have two tables. Table A contains values which should be replaced with values from Table B.
The structure is something like:
A=[1222 1133;1444 1455;]';
B=[1222 1455 1444 1133; 8332 9998 7564 2309]';
Items in Table A should be matched and replaced with items of Column 2 of Table B, i.e. the end product should be:
C= [8332 2309; 7564 9998]';
How can this be done?
Any help is appreciated, I hope the question is clear.

Best Answer

If all elements in A are unique:
A=[1222 1133;1444 1455;]';
B=[1222 1455 1444 1133; 8332 9998 7564 2309]';
[~, idx] = ismember(A, B);
C = B(idx+size(B,1));