breadthdist.m 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. function [R,D] = breadthdist(CIJ)
  2. %BREADTHDIST Reachability and distance matrices
  3. %
  4. % [R,D] = breadthdist(CIJ);
  5. %
  6. % The binary reachability matrix describes reachability between all pairs
  7. % of nodes. An entry (u,v)=1 means that there exists a path from node u
  8. % to node v; alternatively (u,v)=0.
  9. %
  10. % The distance matrix contains lengths of shortest paths between all
  11. % pairs of nodes. An entry (u,v) represents the length of shortest path
  12. % from node u to node v. The average shortest path length is the
  13. % characteristic path length of the network.
  14. %
  15. % Input: CIJ, binary (directed/undirected) connection matrix
  16. %
  17. % Outputs: R, reachability matrix
  18. % D, distance matrix
  19. %
  20. % Note: slower but less memory intensive than "reachdist.m".
  21. %
  22. % Algorithm: Breadth-first search.
  23. %
  24. %
  25. % Olaf Sporns, Indiana University, 2002/2007/2008
  26. N = size(CIJ,1);
  27. D = zeros(N);
  28. for i=1:N
  29. D(i,:) = breadth(CIJ,i);
  30. end;
  31. % replace zeros with 'Inf's
  32. D(D==0) = Inf;
  33. % construct R
  34. R = double(D~=Inf);