MATLAB: Question of a vlookup equivalent in matlab

indexMATLABvlookup

I dont think a vlookup function exists in matlab, but can you guys give me some pointers on how to replicate it? I have a matrix A and vector B, and I want to extract the rows in matrix A into a new matrix C if the A(:,1) is found in vector B. Will I need a loop?
I created C = A( A(:,1) == B(1:end) ,:), but I have a matrix dimesions disagreement. Is there a way to loop through each element of B?

Best Answer

Try this:
>> id = ismember(A(:,1), B)
id =
1
0
1
>> C = A(id,:)
C =
1 2 3 4
8 7 8 9