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

조회 수: 12 (최근 30일)
Nadatimuj
Nadatimuj 2021년 7월 2일
댓글: Nadatimuj 2021년 7월 3일
I want to find the density of a graph in matlab. Is there any function to find that? Thanks.

채택된 답변

Kelly Kearney
Kelly Kearney 2021년 7월 2일
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
Steven Lord
Steven Lord 2021년 7월 3일
You can use the numnodes and numedges functions on a graph or digraph to get the numbers of nodes or edges respectively.
Nadatimuj
Nadatimuj 2021년 7월 3일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by