Find the list of edges between 2 nodes

2 ビュー (過去 30 日間)
Deepa Maheshvare
Deepa Maheshvare 2019 年 11 月 13 日
編集済み: Akira Agata 2019 年 11 月 14 日
I've the following graph with multiple edges.
tail = [1 2 2 4 5 3]
head = [2 4 5 3 3 6]
I would like to know how to find the list of edges between nodes 2 and 3.
Expected output = [2 4 3]
[2 5 3]
I tried using shortestpath for simple graphs. But for multigraph it gives one path. I'd like to know how to
obtain both paths.

回答 (1 件)

Akira Agata
Akira Agata 2019 年 11 月 14 日
編集済み: Akira Agata 2019 年 11 月 14 日
How about the following?
tail = [1 2 2 4 5 3];
head = [2 4 5 3 3 6];
% Create graph object
G = graph(head,tail);
% Find a shortest path between 2 and 3
path = shortestpath(G,2,3); % <- this returns your expected output : [2 4 3]
% Visualize the result
figure
h = plot(G);
highlight(h,path,'EdgeColor','r','LineWidth',2)

カテゴリ

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

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by