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

25 ビュー (過去 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 Center および File ExchangeGraph 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