Finding Rows where a condition is satisfied

I have a 2 column matrix (A) consisting of id numbers in each column to a length of around 5000
I have two smaller column vectors (B & C) which lists a smaller section of id's.
In the first case I want to find rows in A which include an id found in B.
In the second case I want to find rows in A which contain an id found in B & C, or C & B (column order doesn't matter).
I have attempted this by:
[ia ib] = ismember(A(:,1), B);
But this checks only if B is in the first column, ignoring entries where it may be in the second. I would like the rows where one column contains an id from B to then added to a new matrix, D.
I'm looking at doing the same if a row has an id from B and C (not just one column, either column in either order) and adding this information to new matrix E.
Kind Regards,
Dwayne

댓글 수: 1

This is not correct.
>> [ia, ib ] = ismember(4, [1 2; 3 4])
ia =
logical
1
ib =
4
4 only occurs in the second column of B, but it was found.
When you use ismember() without the 'rows' option, then the second argument is treated as-if you had used (:) with it, like ismember(A(:,1), B(:))
If you are not getting a match then it is for some other reason.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2019년 9월 10일

댓글:

2019년 9월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by