MATLAB: Find rows where one column value matches with any value inside another array

arrayfindmatrix

I am new to Matlab, so please respond even if the question is trivial
I have a matrix. Lets say matrix is
A =[
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1]
I have an array. Lets say array is
B = [3, 6, 15]
I want to find out all the rows of Matrix A where column 3 value of Matrix A matches with any value mentioned in the array B. In the above case output will be
ans = [
16 2 3 13
9 7 6 12
4 14 15 1]
I don't want to use loop for this calculation. Is there any built in function which does this.
Thanks

Best Answer

This works:
A =[16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1];
B = [3, 6, 15];
idx = ismember(A(:,3),B);
Result = A(idx,:)
Result =
16 2 3 13
9 7 6 12
4 14 15 1