delete a row with condition

1 回表示 (過去 30 日間)
ha ha
ha ha 2017 年 9 月 5 日
編集済み: ha ha 2017 年 9 月 5 日
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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!