forked from brain-networks/KSmodel_fMRIdynamics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid_communities.m
46 lines (43 loc) · 1.53 KB
/
grid_communities.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function [X,Y,indsort] = grid_communities(c)
% GRID_COMMUNITIES Outline communities along diagonal
%
% [X Y INDSORT] = GRID_COMMUNITIES(C) takes a vector of community
% assignments C and returns three output arguments for visualizing the
% communities. The third is INDSORT, which is an ordering of the vertices
% so that nodes with the same community assignment are next to one
% another. The first two arguments are vectors that, when overlaid on the
% adjacency matrix using the PLOT function, highlight the communities.
%
% Example:
%
% >> load AIJ; % load adjacency matrix
% >> [C,Q] = modularity_louvain_und(AIJ); % get community assignments
% >> [X,Y,INDSORT] = fcn_grid_communities(C); % call function
% >> imagesc(AIJ(INDSORT,INDSORT)); % plot ordered adjacency matrix
% >> hold on; % hold on to overlay community visualization
% >> plot(X,Y,'r','linewidth',2); % plot community boundaries
%
% Inputs: C, community assignments
%
% Outputs: X, x coor
% Y, y coor
% INDSORT, indices
%
% Richard Betzel, Indiana University, 2012
%
%#ok<*AGROW>
nc = max(c);
[c,indsort] = sort(c);
X = [];
Y = [];
for i = 1:nc
ind = find(c == i);
if ~isempty(ind)
mn = min(ind) - 0.5;
mx = max(ind) + 0.5;
x = [mn mn mx mx mn NaN];
y = [mn mx mx mn mn NaN];
X = [X, x];
Y = [Y, y];
end
end