How to highlight single edges in an undirected graph?

4 views (last 30 days)
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?

Accepted Answer

Christine Tobler
Christine Tobler on 8 Oct 2021
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)
e = findedge(g, 1, 2)
e = 2×1
1 2
p = plot(g);
highlight(p, 'Edges', e(1))

Sign in to comment.

More Answers (0)


Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!