フィルターのクリア

How can the edges on the shortestpath be determined?

2 ビュー (過去 30 日間)
CO
CO 2022 年 6 月 27 日
コメント済み: Steven Lord 2022 年 6 月 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

採用された回答

Chunru
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)
plt =
GraphPlot with properties: NodeColor: [0 0.4470 0.7410] MarkerSize: 4 Marker: 'o' EdgeColor: [0 0.4470 0.7410] LineWidth: 0.5000 LineStyle: '-' NodeLabel: {'1' '2' '3' '4' '5' '6' '7' '8'} EdgeLabel: {} XData: [0.3082 1.2885 -0.4680 0.3105 -0.5963 -0.7564 1.3653 -1.4518] YData: [0.7918 0.5124 -0.4892 -0.4894 -1.4376 0.2944 1.5685 -0.7508] ZData: [0 0 0 0 0 0 0 0] Show all properties
[P, d, edgepath] = shortestpath(G,7,8)
P = 1×5
7 1 3 5 8
d = 4
edgepath = 1×4
11 2 5 8
E = G.Edges(edgepath, :)
E = 4×1 table
EndNodes ________ 7 1 1 3 3 5 5 8
highlight(plt, 'Edges', edgepath)
  2 件のコメント
CO
CO 2022 年 6 月 30 日
Chunru, thank you very much for the answer.
In fact I had tried the code in Matlab. But it did not work. By the way, I noticed that my Matlab is Matlab2017.
After that, I installed Matlab2020. It works.
Thanks
CO
Steven Lord
Steven Lord 2022 年 6 月 30 日
That makes sense. The third output argument from shortestpath was introduced in release R2018a.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by