How to distinguish specific nodes in an undirected graph ?
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello,
I have an attribute of an undirected graph called G.Nodes.Load. Where in every time step some of its values change to -inf. And I'm trying to visualize this process using Graph and Network Algorithms.
I tried the following:
figure; h = plot(G);
highlight(h, G.Nodes.Load == -inf, 'NodeColor','r' )
Kindly check the attached graph plots. Is there a clearer way than this?
EDIT : I assigned random values for "G.Nodes.Load", and then I created another attribute "G.Nodes.Capacity" :
Load = (1000-800)*rand(5000,1)+800;
Capacity = (1+0.2) * Load;
G.Nodes.Load = Load;
G.Nodes.Capacity = Capacity;
Now I'm trying to assigne a red color for any value of Load that exceeds its corresponding capacity, a lighter red color for 80% usage of capacity (Load./capacity), light blue for 50% usage, and dark blue for 25% usage. I think in this case I don't have to highlight the nodes but instead I need to choose another way in visualizing the load./capacity ratio, am I correct?
Thanks!
댓글 수: 0
채택된 답변
Steven Lord
2022년 2월 22일
Create a sample graph and define some sample load and capacity data.
rng default
G = graph(bucky);
Load = (1000-800)*rand(numnodes(G),1)+800;
Capacity = (1+0.2*rand(numnodes(G), 1)) .* Load;
Set the node data to the Nodes table in G.
G.Nodes.ID = (1:numnodes(G)).';
G.Nodes.Load = Load;
G.Nodes.Capacity = Capacity;
G.Nodes.Usage = G.Nodes.Load ./ G.Nodes.Capacity;
Plot the graph.
h = plot(G);
Select some nodes.
nodesGreaterThan97Percent = G.Nodes.Usage > 0.97;
Get info about these nodes.
info = G.Nodes(nodesGreaterThan97Percent, :)
Highlight the selected nodes in the plot.
highlight(h, nodesGreaterThan97Percent, 'NodeColor', 'r')
추가 답변 (1개)
Sulaymon Eshkabilov
2022년 2월 21일
Here one potential err in your code is logical (==). One can determine when the value of a variable goes to infinity with this fcn: isinf().
Moreover, MATLAB plot fcn skips infinity values and thus, you'd need to determine when the values go to infinity and assign them some specific value in order to plot them. And then you can do some highlights.
참고 항목
카테고리
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!