forked from yetianmed/subcortex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbreadthdist.m
39 lines (34 loc) · 1.07 KB
/
breadthdist.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
function [R,D] = breadthdist(CIJ)
%BREADTHDIST Reachability and distance matrices
%
% [R,D] = breadthdist(CIJ);
%
% The binary reachability matrix describes reachability between all pairs
% of nodes. An entry (u,v)=1 means that there exists a path from node u
% to node v; alternatively (u,v)=0.
%
% The distance matrix contains lengths of shortest paths between all
% pairs of nodes. An entry (u,v) represents the length of shortest path
% from node u to node v. The average shortest path length is the
% characteristic path length of the network.
%
% Input: CIJ, binary (directed/undirected) connection matrix
%
% Outputs: R, reachability matrix
% D, distance matrix
%
% Note: slower but less memory intensive than "reachdist.m".
%
% Algorithm: Breadth-first search.
%
%
% Olaf Sporns, Indiana University, 2002/2007/2008
N = size(CIJ,1);
D = zeros(N);
for i=1:N
D(i,:) = breadth(CIJ,i);
end;
% replace zeros with 'Inf's
D(D==0) = Inf;
% construct R
R = double(D~=Inf);