필터 지우기
필터 지우기

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 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