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

9 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by