density_und.m 726 B

12345678910111213141516171819202122232425262728
  1. function [kden,N,K] = density_und(CIJ)
  2. % DENSITY_UND Density
  3. %
  4. % kden = density_und(CIJ);
  5. % [kden,N,K] = density_und(CIJ);
  6. %
  7. % Density is the fraction of present connections to possible connections.
  8. %
  9. % Input: CIJ, undirected (weighted/binary) connection matrix
  10. %
  11. % Output: kden, density
  12. % N, number of vertices
  13. % K, number of edges
  14. %
  15. % Notes: Assumes CIJ is undirected and has no self-connections.
  16. % Weight information is discarded.
  17. %
  18. %
  19. % Olaf Sporns, Indiana University, 2002/2007/2008
  20. % Modification history:
  21. % 2009-10: K fixed to sum over one half of CIJ [Tony Herdman, SFU]
  22. N = size(CIJ,1);
  23. K = nnz(triu(CIJ));
  24. kden = K/((N^2-N)/2);