Ordering edge names in Digraph

조회 수: 5 (최근 30일)
Antoine Lunaire
Antoine Lunaire 2020년 9월 6일
댓글: Antoine Lunaire 2020년 9월 8일
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
Antoine Lunaire
Antoine Lunaire 2020년 9월 8일
Thank you very much, this was very easy explained and very helpful

댓글을 달려면 로그인하십시오.

채택된 답변

Christine Tobler
Christine Tobler 2020년 9월 8일
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개)

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by