MATLAB: Efficient way of setting up a substitution table

substitutions changem tables

I have a straightforward problem but I am looking for a more efficient way to set it up. The data set I am using is very large, but for example sake: I have 2 nx2 matrices. The first has 1 column of index values and the other of random values
A=
1 5
2 3
3 1
4 5
5 2
The second has a list of random substitutions:
1 1.24
2 2.67
3 3.88
4 4.22
5 5.23
I would like to assign the substitutions from matrix B to the second column of Matrix A so it would read:
1 5.23
2 3.88
3 1.24
4 5.23
5 2.67
I have tried using changem but I am wondering what is the best way to go about this. Thanks in advance

Best Answer

[tf, idx] = ismember(A(:,1), B(:,1));
A(tf,2) = B(idx(tf),2);