Clear Filters
Clear Filters

How to find graph density in MATLAB for a given graph G?

11 views (last 30 days)
I want to find the density of a graph in matlab. Is there any function to find that? Thanks.

Accepted Answer

Kelly Kearney
Kelly Kearney on 2 Jul 2021
You can simply calculate the number of non-zero elements relative to total elements in the adjacency matrix:
Steven Lord
Steven Lord on 3 Jul 2021
You can use the numnodes and numedges functions on a graph or digraph to get the numbers of nodes or edges respectively.
Nadatimuj on 3 Jul 2021
Great, thanks. So this one works too:
graph_density = numedges(G)/numnodes(G) /(numnodes(G) -1)*2 %factor 2 for undirected, factor 1 for directed

Sign in to comment.

More Answers (0)


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!