Ismember for rows or something else

조회 수: 1 (최근 30일)
Rostislav Teryaev
Rostislav Teryaev 2018년 7월 2일
댓글: Rostislav Teryaev 2018년 7월 2일
Hello! I have to matrices a and b:
a = [1 2;
3 4;
5 6;
7 8;
1 2;
9 10]
b = [1 2;
5 6]
Every row in these tables describe one entity (start and target node of graph edge). So, I want to find indices of a where the rows are equal to rows in b. In other words I need to get this:
c = [1, 3, 5]
But when I use
[~, c] = ismember(b, a, 'row')
I get only this:
c = [1, 3]

채택된 답변

Jan
Jan 2018년 7월 2일
편집: Jan 2018년 7월 2일
Simply swap the inputs:
[found, index] = ismember(a, b, 'rows')
result = find(found)
  댓글 수: 2
Rostislav Teryaev
Rostislav Teryaev 2018년 7월 2일
Exactly! Thank you
Rostislav Teryaev
Rostislav Teryaev 2018년 7월 2일
I managed to do this:
a = [1 2;3 4;5 6;7 8;1 2;9 10]
b = [1 2;5 6]
a1 = permute(a,[1 3 2])
b1 = permute(b,[3 1 2])
find(any(all(a1==b1 , 3), 2))
:)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by