フィルターのクリア

Find and remove data from array that does not match 2nd array

9 ビュー (過去 30 日間)
tybo1mos
tybo1mos 2020 年 12 月 14 日
回答済み: Image Analyst 2020 年 12 月 14 日
I have two arrays. Array A has data which I would like to mimimize based on the contents of array B.
For example, Array A is:
[3, 10, 100;
5, 20, 200;
7, 30, 300;
5, 40, 400;
6, 50 500]
Array B is
[6; 7]
I would like to keep only the rows of array A, which match ANY of the contents of array B:
i.e. in Column 1 of Array A, row 3 and row 5 have values which match contents in Array B (6 & 7).
Note: numbers are random, and wil not be in order
So the final result would like to be:
[7, 30, 300;
6, 50 500]

採用された回答

Image Analyst
Image Analyst 2020 年 12 月 14 日
Use ismember():
A = [3, 10, 100;
5, 20, 200;
7, 30, 300;
5, 40, 400;
6, 50 500]
B = [6; 7]
[ia, ib] = ismember(B, A)
C = A(ib,:)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by