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!