How to distinguish specific nodes in an undirected graph ?

1 回表示 (過去 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 Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by