Ismember for rows or something else

2 次查看(过去 30 天)
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
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