フィルターのクリア

Number of k-stars in an adjacency matrix

1 回表示 (過去 30 日間)
Daniel Stocks
Daniel Stocks 2021 年 1 月 25 日
コメント済み: Daniel Stocks 2021 年 1 月 28 日
Hi all,
I have an nxn adjacency matrix of a graph and want to know the number of unique 2-stars, 3-stars and triangles in the graph, is there a function I can use to do this or do code my own method?
I have to code my own method any advise on how to proceed would be appreciated.
Thank you

回答 (1 件)

Gaurav Garg
Gaurav Garg 2021 年 1 月 28 日
Hi Daniel,
Even though you can find such patterns easily in 1-D arrays by converting them to strings (link1 and link2), it would be better if you can write such pattern funcitons for 2-D arrays.
for i=1:r
for j=1:c
answer = check_for_triangle(i,j);
end
end
function check_for_triangle(r, c)
is_present = false;
if A(r,c) == 1
if A(r+1,c) == 1 & A(r+1,c+1) == 1
if A(r+2,c) == 1 & A(r+2,c+1) == 1 & A(r+2,c+2) == 1
is_present = true;
end
end
end
end
The above given pseudo-code is an example of how you can write code pattern to check for a triangle in a binary adjacency matrix.
  1 件のコメント
Daniel Stocks
Daniel Stocks 2021 年 1 月 28 日
Thank you Gaurav I will look into this

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by