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

16 vues (au cours des 30 derniers jours)
Commenté : Nadatimuj le 3 Juil 2021
I want to find the density of a graph in matlab. Is there any function to find that? Thanks.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Kelly Kearney le 2 Juil 2021
You can simply calculate the number of non-zero elements relative to total elements in the adjacency matrix:
##### 3 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Steven Lord le 3 Juil 2021
You can use the numnodes and numedges functions on a graph or digraph to get the numbers of nodes or edges respectively.
Great, thanks. So this one works too:
%http://reference.wolfram.com/language/ref/GraphDensity.html
graph_density = numedges(G)/numnodes(G) /(numnodes(G) -1)*2 %factor 2 for undirected, factor 1 for directed

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by