Looking for all sub-networks among a network

조회 수: 3 (최근 30일)
Benson Gou
Benson Gou 2018년 10월 24일
댓글: Guillaume 2018년 10월 24일
Dear All,
For a given network formed by lines and edges, how can I quickly find out all sub-networks? There is no connection among two sub-networks.
For example, the lines are given in a matrix A:
I know the sub-networks are: {6 2 3 4 5 7}, {1 8}. But how can I quickly find them out?
Thanks a lot. Benson

채택된 답변

Guillaume
Guillaume 2018년 10월 24일
Please don't post screenshots, particularly as it's trivial to write your matrix as text in the question. We can't copy/paste screenshots into matlab.
It is trivial to find the number of components in a graph, using matlab's graph functions, in particular graph.conncomp:
A = [6 2
6 3
2 3
4 5
6 4
1 8
2 7]
g = graph(A(:, 1), A(:, 2));
max(conncomp(g))
  댓글 수: 2
Benson Gou
Benson Gou 2018년 10월 24일
편집: Benson Gou 2018년 10월 24일
Guillaume,
Thanks for your response. What I want to obtain are the edge ID in each sub-network. For this example, I want to obtain the edges in each sub-network: sub1 = {6 2 3 4 5 7}; sub2 = {1 8}.
Thanks anyway.
Guillaume
Guillaume 2018년 10월 24일
You mean the node ID.
This is easily obtained with conncomp:
bin = conncomp(g);
accumarray(bin', (1:numel(bin))', [], @(nodes) {nodes'})

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Construction에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by