View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Find Network Components

4.8 | 4 ratings Rate this file 25 Downloads (last 30 days) File Size: 4.14 KB File ID: #42040 Version: 1.2

Find Network Components



31 May 2013 (Updated )

Find network components, sizes, and lists of member nodes.

| Watch this File

File Information

Given an undirected network represented by an adjacency matrix, we may wish to find that network's
- largest component
- number of components
- list of which nodes are in which component together.
This code computes these rapidly (linear in the number of nodes) and accurately. The code is commented so that if you wish to modify it, you may do so.

1. Network adjacency matrix.

1. Number of network components
2. Sizes of network components (sorted, descending)
3. Membership list of each component (sorted by component size, descending).

Code includes a couple examples of usage at the top. I have tested this in R2014a, but it uses nothing fancy, and I believe it to be backward compatible for many years.

Required Products MATLAB
MATLAB release MATLAB 8.1 (R2013a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
30 Jan 2017 Nima Moshtagh

19 Jan 2015 Marwa Mansri

good work

Comment only
26 Apr 2014 Alphab

Alphab (view profile)

Great work!

Comment only
26 Apr 2014 Wolfgang Schwanghart

Hi, you might also want to take a look at Tim Davis' function find_components:
find_components uses the builtin function dmperm to find connected components.

Comment only
24 Apr 2014 Daniel Larremore

Iro, suggestion appreciated. The code removes diagonal elements already, but I have edited the example anyway.

Comment only
24 Mar 2014 Iro

Iro (view profile)

Hi, it seems to work for a given adjacency matrix, but you might want to edit the example of creating a random one because it is possible that it generates ones in the diagonal.

13 Aug 2013 Li

Li (view profile)

30 Jul 2013 TCH

TCH (view profile)

05 Jun 2013 1.1

Fixed typo in description.

24 Apr 2014 1.2

Fixed typos (clarity), removed possibility of self-edges in the example (clarity), changed instances of "cluster" to "component" in comments and variable names (clarity and correctness), and sorted outputs by component sizes (ease of use).

Contact us