How to list all isolated vertices and remove it from the graph?
25 views (last 30 days)
Show older comments
Shanmugavelan S
on 17 Dec 2021
Answered: Shanmugavelan S
on 18 Dec 2021
I have a Graph with several isolated vertices. I want to deleted these from the generated output.
0 Comments
Accepted Answer
Steven Lord
on 17 Dec 2021
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 Comments
Steven Lord
on 17 Dec 2021
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
More Answers (1)
See Also
Categories
Find more on Directed Graphs in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!