How to distinguish specific nodes in an undirected graph ?
3 views (last 30 days)
Show older comments
Waseem AL Aqqad
on 21 Feb 2022
Commented: Waseem AL Aqqad
on 24 Feb 2022
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 Comments
Accepted Answer
Steven Lord
on 22 Feb 2022
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')
More Answers (1)
Sulaymon Eshkabilov
on 21 Feb 2022
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.
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!