Get Community matrix from affiliation vector 'cs'
Updated 16 May 2017

View License


C = getCommunityMatrix(cs)

Given a community affiliation vector cs (obtained from some modularity or
community-detection code in the Brain Connectivity Toolbox [1], for example),
of size 1-by-N, the code returns a N-by-N matrix where pairs of nodes
belonging to the same community are given the same number. Remember that
the actual number assigned to each community is arbitrary, and that each
node (and also each pair of nodes) can be assigned to only one community,
i.e. the communities are non-overlapping. Diagonal elements are set to 0.

NOTE: in order to visualize the matrix, one may want first to convert the
zeros in NaNs, using C(C==0) = nan, and then pcolor(C)


cs : community affiliation vector <1 x N>


C : Community Matrix <N x N>


[1] Brain Connectivity Toolbox:

Cite As

Ruggero G. Bettinardi (2024). getCommunityMatrix(cs) (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Test and Measurement in Help Center and MATLAB Answers
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes