delete a row with condition

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

采纳的回答

Image Analyst
Image Analyst 2017-9-5
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, :)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!