How can the edges on the shortestpath be determined?
2 次查看(过去 30 天)
显示 更早的评论
After using shortestpath (Dijkstra algorithm) on directed and weighted graph, Matlab gives the node sequence on the shortest path.
How can I write the edges on the shortest path?
Thanks
CO
0 个评论
采纳的回答
Chunru
2022-6-27
编辑:Chunru
2022-6-28
s = [1 1 2 3 3 4 4 6 6 7 8 7 5];
t = [2 3 4 4 5 5 6 1 8 1 3 2 8];
G = digraph(s,t);
plt = plot(G)
[P, d, edgepath] = shortestpath(G,7,8)
E = G.Edges(edgepath, :)
highlight(plt, 'Edges', edgepath)
更多回答(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!