find an element in a pair and return the counterpart
2 次查看(过去 30 天)
显示 更早的评论
I have a pair matrix: for example node_pair_list=[ [1, 2];[2, 3]; [4, 3]; [3, 6]; [5, 6] ]. Note: each pair is unique, [3, 4] is equivalent to [4, 3] but this pair will only appear once. Now I have a single element 3 (current_node) for example, I want to check whether 3 contains in any of these pairs. And then find the corresponding element (counterpart)paired with 3. For example in this case, the pair found is [2, 3], [4, 3], [3, 6] and the counterpart is 2, 4 and 6. How can I do this easily, vectorizely? Thank you very much!
0 个评论
采纳的回答
Azzi Abdelmalek
2015-8-19
node_pair_list= [1, 2;2, 3; 4, 3; 3, 6; 5, 6 ]
idx=ismember(node_pair_list,3)
out=node_pair_list(any(idx,2),:)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!