How to generate the following Graph in MATLAB ?
1 次查看(过去 30 天)
显示 更早的评论
Hello all, I am trying to generate the following graph shown in image and compute the shortest distance between each nodes but not getting correctly. Specifically I am able to generate the graph with the code shown below but not able to compute shortest distance between each nodes.
sr = [1,2,2,2,3,3,3,4,5];
ta = [2,3,6,8,6,4,7,6,6];
G = graph(sr,ta);
plot(G)
Any help in this regard will be highly appreciated.
采纳的回答
Dyuman Joshi
2023-4-21
sr = [1,2,2,2,3,3,3,4,5];
ta = [2,3,6,8,6,4,7,6,6];
G = graph(sr,ta);
%The (i,j) elemenet is the shortest distance between node i and node j
d = distances(G)
plot(G)
更多回答(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!