delete a row with condition

1 visualización (últimos 30 días)
ha ha
ha ha el 5 de Sept. de 2017
Editada: ha ha el 5 de Sept. de 2017
Let's say:
A=[ 1 222 ----> labelling "1"
2 555 ----> labelling "2"
3 999 ----> labelling "3"
4 3333 ----> labelling "4"
6 111 ----> labelling "5"
7 5000 ----> labelling "6"
8 2000] ----> labelling "7"
and
B=[ 3; 7];
I wanna delete the row in matrix A in which the first column have the same value as value in matrix B
The result (C) will as follow:
A=[ 1 222
2 555
3 999 ----> delete this row
4 3333
6 111
7 5000 ----> delete this row
8 2000]
Ww have:
C=[ 1 222
2 555
4 3333
6 111
8 2000]
How to do it?

Respuesta aceptada

Image Analyst
Image Analyst el 5 de Sept. de 2017
Use ismember() to figure out what rows, then [] to extract all but those rows
A=[ 1 222
2 555
3 999 %----> delete this row
4 3333
6 111
7 5000 %----> delete this row
8 2000]
B=[ 3 7];
[ia, ib] = ismember(A(:, 1), B)
A = A(~ia, :)

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!