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

2 次查看(过去 30 天)
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

采纳的回答

Birdman
Birdman 2018-2-14
Z=A(~ismember(A(:,1),B),:)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by