Error using matlab.graphics.chart.primitive.GraphPlot/highlight>checkEdgesNodePair
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Eugen Fekete
le 4 Jan 2022
Commenté : Eugen Fekete
le 5 Jan 2022
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')
0 commentaires
Réponse acceptée
Steven Lord
le 4 Jan 2022
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)
successors(G, 1)
findedge(G, 1, 6)
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
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.Nodes.Name
findedge(G2, 1, 6) % There is an edge between 'a' and 'f'
2 commentaires
Steven Lord
le 5 Jan 2022
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"])
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!