Error using matlab.graphics.chart.primitive.GraphPlot/highlight>checkEdgesNodePair
5 ビュー (過去 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')
0 件のコメント
採用された回答
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)
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 件のコメント
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"])
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Graph and Network Algorithms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!