Extract subgraph by specifying edges

3 ビュー (過去 30 日間)
Kamal Premaratne
Kamal Premaratne 2022 年 2 月 17 日
コメント済み: Kamal Premaratne 2022 年 2 月 21 日
I have a digraph G from which I want to extract a subgraph by specifying specific edges (not vertices). As an example, suppose G has the following edge table:
EndNodes Weight Label
-------------- --------- --------
1 2 1 1
1 3 2 1
4 1 3 1
4 2 4 1
4 3 5 2
4 5 6 2
5 6 7 2
5 7 8 2
7 6 9 1
Each edge has a weight and also a label. I want to extract the digraph which has the edges with, say, label 2 only. The subgraph command allows one to extract the subgraph by specifying the nodes, but not edges (as far as I know). I can of course use
>> EdgeTable = G.Edges(G.Edges.label == 2, :)
>> G_subgraph = digraph(EdgeTable);
But this does not transfer the node properties that the nodes may have in G's node table (e.g., G.Nodes.Color, etc.).
Any assistance would be greatly appreciated. Thank you.
-- Kamal

採用された回答

Anshika Chourasia
Anshika Chourasia 2022 年 2 月 21 日
Hi Kamal,
I understand you want to extract subgraph by specifying specific edges.
Possible workaround for this problem is to have a vector named “EdgeNumber” containing the edge numbers for the interested label value and then store the end nodes in “EndNode” corresponding to those edges. Then, using the normal procedure to extract subgraph that contains only the nodes specified by “EndNode”.
Please refer this link for more information on extracting a subgraph through selected edges.
  1 件のコメント
Kamal Premaratne
Kamal Premaratne 2022 年 2 月 21 日
Thank you Anshika. Yes, I think you are right in that the best way is to copy the full digraph to another variable and then remove from it the edges that are not needed. As far as I can see, this is the only way to retain the node and edge properties in the subgraph.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by