MATLAB: Compare two columns and retrive joint values

comparisonismemmberjoint

Hi, I have two data sets which I want to compare and retrieve corresponding data:
A1=[726834;726835;726836;726837;726838];
A2=[7;68;36;37;8];
B1=[726835;726838;727000];
B2=[5;6;8];
I want to create a joint data set that will search B1 into A1, retrieve corresponding A2 value and joint it to B2 so that resulting data set is in this example would be:
C=[68 5;8 6];
Thank you a lot!
%so far I am stucked here
[idm,idx] = ismember(A1,B1);
A1(idm) = B2(idx(idm));
Thanks!

Best Answer

[found, where] = ismember(B1, A1); %note the order of the inputs!
assert(all(found), 'Some values of B1 not in A1');
C = [A2(where), B2]