delete a row with condition

1 Ansicht (letzte 30 Tage)
ha ha
ha ha am 5 Sep. 2017
Bearbeitet: ha ha am 5 Sep. 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?

Akzeptierte Antwort

Image Analyst
Image Analyst am 5 Sep. 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, :)

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!