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

23 visualizaciones (últimos 30 días)
Nadatimuj
Nadatimuj el 2 de Jul. de 2021
Comentada: Nadatimuj el 3 de Jul. de 2021
I want to find the density of a graph in matlab. Is there any function to find that? Thanks.

Respuesta aceptada

Kelly Kearney
Kelly Kearney el 2 de Jul. de 2021
You can simply calculate the number of non-zero elements relative to total elements in the adjacency matrix:
nnz(adjacency(G))./numel(adjacency(G))
  3 comentarios
Steven Lord
Steven Lord el 3 de Jul. de 2021
You can use the numnodes and numedges functions on a graph or digraph to get the numbers of nodes or edges respectively.
Nadatimuj
Nadatimuj el 3 de Jul. de 2021
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graph and Network Algorithms en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by