MATLAB: Compare two matrices of different dimensions

fillfind

I have two matrices A=500000*4 and B=4300000*4.
Matrix A = id, plus 3 columns of NaN.
Matrix B = id, lat, lon, elev.
I would like to find the id values in A = B, and based on those same id values, fill matrix A with the missing lat,lon,elev.
The code I have is:
for i=1:length(A)
ind = B(:,1)==A(i,1);
A(i,2:4) = B(ind,2:4);
clear ind
end
This works but is extremely slow. How can I do this more efficiently?
Thanks
Jon

Best Answer

I fiddled around with this further and addressed the loop, which was re-doing the "find" and settled on this...
C=A(:,1);
D=B(:,1);
idx=find(ismember(C,D));
A(:,2)=B(idx,2);
A(:,3)=B(idx,3);
A(:,4)=B(idx,4);
seems to work.