How to highlight single edges in an undirected graph?

3 ビュー (過去 30 日間)
laha_M
laha_M 2021 年 10 月 8 日
コメント済み: laha_M 2021 年 10 月 9 日
I am plotting an undirected graph where there exist multiple edges between the same nodes. Now I want to highlight a few of the edges. But only a single edge needs to be highlighted (anyone among the multiple edges between the same node). How do I do that?
I am attaching one graph. You can see both the edges get highlighted in red if two edges exist connecting the same nodes. Instead, I want to highlight only one edge (anyone) and keep the rest of the edges unhighlighted. How to do it for an undirected graph?
Thanks.

採用された回答

Christine Tobler
Christine Tobler 2021 年 10 月 8 日
Do you still want the multiple edges to be displayed? If not, you can use the simplify command to reduce all multiple edges to just one.
Otherwise, here is one way to do this:
g = graph([1 1 2 2 3 3], [2 2 3 3 1 1], 'omitselfloops');
p = plot(g);
highlight(p, 1, 2)
figure;
e = findedge(g, 1, 2)
e = 2×1
1 2
p = plot(g);
highlight(p, 'Edges', e(1))
  3 件のコメント
Christine Tobler
Christine Tobler 2021 年 10 月 9 日
In that case, you'll need to use the second output of findedge, which in the case of multiple edges tells us which node pair each edge id is coming from:
g = graph([1 1 2 2 3 3], [2 2 3 3 1 1], 'omitselfloops');
p = plot(g);
highlight(p, 1, 2);
s = [1 3];
t = [2 1];
figure;
[e, stID] = findedge(g, s, t)
e = 4×1
1 2 3 4
stID = 4×1
1 1 2 2
[~,uniqueSTid] = unique(stID)
uniqueSTid = 2×1
1 3
p = plot(g);
highlight(p, 'Edges', e(uniqueSTid));
laha_M
laha_M 2021 年 10 月 9 日
Thanks.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by