Ordering edge names in Digraph
4 views (last 30 days)
Show older comments
Antoine Lunaire
on 6 Sep 2020
Commented: Antoine Lunaire
on 8 Sep 2020
I have this simple code just to make the question easy
s = [1 1 1 1 2 2 3 1 1];
t = [1 1 2 4 3 4 4 1 1];
G = digraph(s,t);
G.Nodes.Name = {'First', 'Second', 'Third' ,'Fourth'}';
G.Edges.Power = {'loop1' 'loop2' 'Hi' 'Hello' 'Bonjour' 'Welcome' 'Salut' 'loop3' 'loop4'}';
figure;
p = plot(G,'EdgeLabel',G.Edges.Power);
And this gives me the following graph.
My problem is I receive the the order of the source and destination vectors in a similar way to the given above, where I can not control the selfloops of (1,1). Some of them comes at the begining, some in the middel and some at the end. I want to give the same order of Edges.Power to the same order of the edges are defined by s,t. In other words, all selfloops around vertix 1(First) should be 'loop1' , 'loop2', 'loop3', loop4'.
Any help will be highly appreciated and thanks in advance.
Accepted Answer
Christine Tobler
on 8 Sep 2020
The edges are reordered in the graph constructor, but it looks like the Power variable you're assigning is in the same order as the s, t vectors being passed in. You can pass the Power vector into the constructor, this way it will be reordered together with s and t:
s = [1 1 1 1 2 2 3 1 1];
t = [1 1 2 4 3 4 4 1 1];
nodeNames = {'First', 'Second', 'Third' ,'Fourth'}';
Power = {'loop1' 'loop2' 'Hi' 'Hello' 'Bonjour' 'Welcome' 'Salut' 'loop3' 'loop4'}';
G = digraph(s, t, table(Power), nodeNames);
plot(G, 'EdgeLabel', G.Edges.Power)
0 Comments
More Answers (0)
See Also
Categories
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!