MATLAB: Delete rows from matrix that contain values that correspond to values from a separate variable vector

arraydelete rowsindicesMATLABmatrixvector

Hi,
I wish to remove rows from a matrix A [n x 2] that contains any value from another vector B [1 x n] in its first column. The values in vector B change depending on my problem, I am therefore looking for a solution that can read the values in the B vector and apply the modification automatically to the A matrix.
An example B vector is shown below:
B = [2, 3, 5, 8, 10]
Along with an example A matrix:
A = [ 1 2;
2 3;
2 4;
3 1;
3 4;
4 2;
4 9;
5 1;
5 7;
6 2;
6 3;
6 4;
8 2;
8 9;
9 1;
9 6;
10 6]
The desired output matrix Z [n x 2] would be as follows:
Z = [ 1 2;
4 2;
4 9;
6 2;
6 3;
6 4;
9 1;
9 6]
Any help would be appreciated. I am using this solution as part of a meshing algorithm that I am developing, where matrix Z forms the connectivity between nodes.
Thanks in advance, Sam

Best Answer

Z=A(~ismember(A(:,1),B),:)