Plotting an undirected graph gives me only unconnected dots.
Show older comments
I have an undirected graph of 7618 edges that I want to plot. I put the first set of nodes of each edge in nodes1 and the other set of nodes of each edge in nodes2 and:
G= graph(nodes1,nodes2)
plot(G)
This is the plot I get

Why aren't the nodes connected like they are supposed to except from those in the bottom left? How do I fix it to get the results I want?
Matlab R2016a
Accepted Answer
More Answers (1)
Steven Lord
on 6 Jan 2019
It's going to be impossible to give a specific answer without seeing your nodes vectors (or a small sample of the nodes vectors.)
But generally, this indicates most of your nodes aren't connected to any other edges. If I had to guess I'd say that you have one element in either nodes1 or nodes2 that is larger than the others, meaning MATLAB will add isolated nodes up to that maximum value. Consider:
G = graph(7, 8);
plot(G)
You may expect G has exactly two nodes, labeled 7 and 8. It actually has eight where nodes 1 through 6 aren't connected to anything else.
Categories
Find more on Undirected Graphs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!