Error using matlab.gra​phics.char​t.primitiv​e.GraphPlo​t/highligh​t>checkEdg​esNodePair

조회 수: 4 (최근 30일)
I've been trying to add colors to my graph's edges, but I got this error and I have no idea how to solve it:
Error using matlab.graphics.chart.primitive.GraphPlot/highlight>checkEdgesNodePair
s and t must specify edges in the graph.
Error in matlab.graphics.chart.primitive.GraphPlot/highlight
Error in asd (line 10)
highlight(p,[1 1 1 1 1],[1 2 3 4 6],'EdgeColor','r')
clear all
close all
clc
s = {'a' 'a' 'a' 'a' 'a' 'b' 'b' 'b' 'b' 'c' 'c' 'c' 'd' 'd' 'd' 'e' 'e' 'e' 'e' 'f' 'f' 'f' 'f' 'g' 'g' 'g' 'g' 'g'};
t = {'a' 'b' 'c' 'd' 'f' 'a' 'c' 'd' 'g' 'b' 'c' 'e' 'c' 'a' 'b' 'e' 'c' 'b' 'g' 'a' 'b' 'd' 'e' 'g' 'a' 'c' 'd' 'e'};
G = digraph(s,t);
labels = {'a/5' 'a/5' 'a/5' 'a/5' 'a/5' 'b/4' 'b/4' 'b/4' 'b/4' 'c/3' 'c/3' 'c/3' 'd/3' 'd/3' 'd/3' 'e/4' 'e/4' 'e/4' 'e/4' 'f/4' 'f/4' 'f/4' 'f/4' 'g/5' 'g/5' 'g/5' 'g/5' 'g/5'};
p = plot(G,'Layout','layered','EdgeLabel',labels);
highlight(p,[1 1 1 1 1],[1 2 3 4 6],'EdgeColor','r')
highlight(p,[2 2 2 2],[1 2 4 7],'EdgeColor','g')
highlight(p,[3 3 3],[2 3 5],'EdgeColor','b')
highlight(p,[4 4 4],[1 2 3],'EdgeColor','c')
highlight(p,[5 5 5 5],[2 3 5 7],'EdgeColor','m')
highlight(p,[6 6 6 6],[1 2 4 5],'EdgeColor','y')
highlight(p,[7 7 7 7 7],[7 1 3 4 5],'EdgeColor','k')
title('PageRank Hivatkozások közti átmenet')

채택된 답변

Steven Lord
Steven Lord 2022년 1월 4일
s = {'a' 'a' 'a' 'a' 'a' 'b' 'b' 'b' 'b' 'c' 'c' 'c' 'd' 'd' 'd' 'e' 'e' 'e' 'e' 'f' 'f' 'f' 'f' 'g' 'g' 'g' 'g' 'g'};
t = {'a' 'b' 'c' 'd' 'f' 'a' 'c' 'd' 'g' 'b' 'c' 'e' 'c' 'a' 'b' 'e' 'c' 'b' 'g' 'a' 'b' 'd' 'e' 'g' 'a' 'c' 'd' 'e'};
G = digraph(s,t)
G =
digraph with properties: Edges: [28×1 table] Nodes: [7×1 table]
successors(G, 1)
ans = 5×1
1 2 3 4 5
findedge(G, 1, 6)
ans = 0
There is no edge in G from node 1 to node 6 as you can see from both the successors call and the findedge call.
G.Nodes.Name
ans = 7×1 cell array
{'a'} {'b'} {'c'} {'d'} {'f'} {'g'} {'e'}
You may have intended node 6 to be 'f' but it is 'g' instead. If you want them in that order, say so when you construct the digraph.
G2 = digraph(s, t, [], {'a','b','c','d','e','f','g'})
G2 =
digraph with properties: Edges: [28×1 table] Nodes: [7×1 table]
G2.Nodes.Name
ans = 7×1 cell array
{'a'} {'b'} {'c'} {'d'} {'e'} {'f'} {'g'}
findedge(G2, 1, 6) % There is an edge between 'a' and 'f'
ans = 5
  댓글 수: 2
Steven Lord
Steven Lord 2022년 1월 5일
Another option I forgot to mention earlier would be to use node names instead of node indices in your highlight calls.
s = {'a' 'a' 'a' 'a' 'a' 'b' 'b' 'b' 'b' 'c' 'c' 'c' 'd' 'd' 'd' 'e' 'e' 'e' 'e' 'f' 'f' 'f' 'f' 'g' 'g' 'g' 'g' 'g'};
t = {'a' 'b' 'c' 'd' 'f' 'a' 'c' 'd' 'g' 'b' 'c' 'e' 'c' 'a' 'b' 'e' 'c' 'b' 'g' 'a' 'b' 'd' 'e' 'g' 'a' 'c' 'd' 'e'};
G = digraph(s,t);
h = plot(G, 'Layout', 'circle');
highlight(h, ["a", "a"], ["f", "c"])
Eugen Fekete
Eugen Fekete 2022년 1월 5일
This option even makes understanding it easier. Thanks for the helps!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by