Ordering edge names in Digraph

5 visualizaciones (últimos 30 días)
Antoine Lunaire
Antoine Lunaire el 6 de Sept. de 2020
Comentada: Antoine Lunaire el 8 de Sept. de 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 comentario
Antoine Lunaire
Antoine Lunaire el 8 de Sept. de 2020
Thank you very much, this was very easy explained and very helpful

Iniciar sesión para comentar.

Respuesta aceptada

Christine Tobler
Christine Tobler el 8 de Sept. de 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)

Más respuestas (0)

Categorías

Más información sobre Graph and Network Algorithms en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by