Ordering edge names in Digraph

4 vues (au cours des 30 derniers jours)
Antoine Lunaire
Antoine Lunaire le 6 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.
  1 commentaire
Antoine Lunaire
Antoine Lunaire le 8 Sep 2020
Thank you very much, this was very easy explained and very helpful

Connectez-vous pour commenter.

Réponse acceptée

Christine Tobler
Christine Tobler le 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)

Plus de réponses (0)

Catégories

En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by