Looking for all sub-networks among a network
1 次查看(过去 30 天)
显示 更早的评论
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/192481/image.png)
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
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Construction 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!