Find row number of elements

2 ビュー (過去 30 日間)
John Doe
John Doe 2013 年 6 月 1 日
Hi, I have a list of branches, BL, and a list of nodes, nodeList.
BL has two columns, containing to-from nodes for each branch. All elements in nodeList are included at least once in BL.
I want to create a list of branches that are connected to one or more nodes in nodeList.
What I want to achieve:
BL =
1 2
1 3
2 4
3 4
4 5
5 6
nodeList =
1
3
tempBranch =
1
2
4
The way I'm doing it now (below) is very ineffective, so I'm hoping someone knows a better way to do this.
Can I do this without loops?
for j = 1:rows %%rows in BL
if BL(j,1) == nodeList(i) || BL(j,2) == nodeList(i)
tempBranch(k) = j;
k = k + 1;
end
end
Thanks!

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 6 月 1 日
編集済み: Azzi Abdelmalek 2013 年 6 月 1 日
tempBranch =find(any(ismember(BL,nodeList),2))
  1 件のコメント
John Doe
John Doe 2013 年 6 月 1 日
Perfect =) Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOctave についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by