How to list all isolated vertices and remove it from the graph?

27 ビュー (過去 30 日間)
Shanmugavelan S
Shanmugavelan S 2021 年 12 月 17 日
回答済み: Shanmugavelan S 2021 年 12 月 18 日
I have a Graph with several isolated vertices. I want to deleted these from the generated output.

採用された回答

Steven Lord
Steven Lord 2021 年 12 月 17 日
rng default
A = sprandsym(10, (5/100));
G = graph(A, string(1:10)); % Give the nodes names
plot(G)
isolatedNodes = degree(G) == 0;
G2 = rmnode(G, find(isolatedNodes));
figure
plot(G2)
  2 件のコメント
Shanmugavelan S
Shanmugavelan S 2021 年 12 月 17 日
Dear Prof.Steven Lord,
Thank you for your help. I tried your valuable suggestions. B
ut after deleting the isolated vertices. In the 2nd graph, vertices label renamed automatically as 1:n
2nd Graph's Output after isolatedNodes = degree(G) == 0;G2= rmnode(G, find(isolatedNodes)); command
Please help me to get an output without affecting the NodeLabels.
Steven Lord
Steven Lord 2021 年 12 月 17 日
Note how I explicitly gave the nodes names rather than using the default numerical IDs.
G = graph(A, string(1:10)); % Give the nodes names

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

その他の回答 (1 件)

Shanmugavelan S
Shanmugavelan S 2021 年 12 月 18 日
Thank you sir for your suggestion. Is there any alternative command to rename nodes with unequal length for labeling (For eg. Vertices are renamed with prime numbers only)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by