How to distinguish specific nodes in an undirected graph ?

조회 수: 3 (최근 30일)
Waseem AL Aqqad
Waseem AL Aqqad 2022년 2월 21일
댓글: Waseem AL Aqqad 2022년 2월 24일
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!

채택된 답변

Steven Lord
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, :)
info = 9×4 table
ID Load Capacity Usage __ ______ ________ _______ 8 909.38 934.59 0.97302 9 991.5 1021.1 0.97101 31 941.21 955.49 0.98506 32 806.37 815.07 0.98933 36 964.69 989.76 0.97468 39 990.04 992.4 0.99763 52 935.94 951.63 0.98351 55 823.8 848.91 0.97043 59 917.05 931.39 0.98461
Highlight the selected nodes in the plot.
highlight(h, nodesGreaterThan97Percent, 'NodeColor', 'r')

추가 답변 (1개)

Sulaymon Eshkabilov
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.
  댓글 수: 2
Waseem AL Aqqad
Waseem AL Aqqad 2022년 2월 21일
You misunderstood my question.
I'm plotting a Graph object (Complex Network) not data points. So, I'm visulizing the nodes with this attribute G.Nodes.Load = -inf. What I did is quite correct but I'm wondering if there is a better way.
Waseem AL Aqqad
Waseem AL Aqqad 2022년 2월 21일
You might want to check this tutorial Graph and Network Algorithms

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by