Is there more efficient way to find the neighbors of two nodes or more other than using a loop?

4 ビュー (過去 30 日間)
Waseem AL Aqqad
Waseem AL Aqqad 2021 年 6 月 17 日
編集済み: KSSV 2021 年 6 月 23 日
The built in function "neighbors" accepts only scalar inputs, so I wonder if there is more efficient way than performing the following
for ii = 1:length(inActive)
b = neighbors(G_dmg,inActive(ii));
end
I usually concatenate the neighbors of all nodes in one variable, but I cannot tell which nodes are neighbors to node X and which are neighbors to node Y.
b = [];
for ii = 1:length(inActive)
b = [b, neighbors(G_dmg,inActive(ii))];
end
Your ideas would be highly appreciated.
  8 件のコメント
Waseem AL Aqqad
Waseem AL Aqqad 2021 年 6 月 17 日
編集済み: Waseem AL Aqqad 2021 年 6 月 17 日
This is so clever and so fast in providing a solution to my problem. Knock on wood!
Thank you, Christine.
I will let you know what will happen when I update nrActiveNeighbors or when I increase numnodes(G).
Rubel Ahmed
Rubel Ahmed 2021 年 6 月 23 日
編集済み: KSSV 2021 年 6 月 23 日
You can try Knnsearch() from Matlab

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

回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by