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

1 visualización (últimos 30 días)
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

Respuesta aceptada

Birdman
Birdman el 14 de Feb. de 2018
Z=A(~ismember(A(:,1),B),:)

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by