Create a graph with several isolated nodes and a few links
1 次查看(过去 30 天)
显示 更早的评论
Why I am not able to create a graph with several isolated nodes and a few links?
s = [1
1
1];
t = [1
2
3];
XY = [ 1 1.5
1.2 1.7
1.3 1.3
1.7 2.2
1 2
4.2 2.9
3.5 2.5
3.8 2.9
3.8 3.2
3.6 3.1
3 3
3.4 3.4
3 2.3];
G = graph(s,t);
G.Nodes.X = XY(:,1); G.Nodes.Y = XY(:,2);
6 个评论
Dyuman Joshi
2023-10-14
But there are no isolated nodes in your graph -
s = [1
1
1];
t = [1
2
3];
G = graph(s,t);
plot(G)
采纳的回答
Steven Lord
2023-10-14
Your code would work with one minor addition, a line that adds the additional nodes to the graph that are not present in the s and t vectors you use to create the graph.
s = [1
1
1];
t = [1
2
3];
XY = [ 1 1.5
1.2 1.7
1.3 1.3
1.7 2.2
1 2
4.2 2.9
3.5 2.5
3.8 2.9
3.8 3.2
3.6 3.1
3 3
3.4 3.4
3 2.3];
G = graph(s,t);
G = addnode(G, height(XY)-numnodes(G)); % Added
G.Nodes.X = XY(:,1);
G.Nodes.Y = XY(:,2);
Let's plot the graph and see the isolated nodes.
plot(G, 'XData', G.Nodes.X, 'YData', G.Nodes.Y)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!