clustering_coef_bu.m 707 B

12345678910111213141516171819202122232425262728
  1. function C=clustering_coef_bu(G)
  2. %CLUSTERING_COEF_BU Clustering coefficient
  3. %
  4. % C = clustering_coef_bu(A);
  5. %
  6. % The clustering coefficient is the fraction of triangles around a node
  7. % (equiv. the fraction of node's neighbors that are neighbors of each other).
  8. %
  9. % Input: A, binary undirected connection matrix
  10. %
  11. % Output: C, clustering coefficient vector
  12. %
  13. % Reference: Watts and Strogatz (1998) Nature 393:440-442.
  14. %
  15. %
  16. % Mika Rubinov, UNSW, 2007-2010
  17. n=length(G);
  18. C=zeros(n,1);
  19. for u=1:n
  20. V=find(G(u,:));
  21. k=length(V);
  22. if k>=2 %degree must be at least 2
  23. S=G(V,V);
  24. C(u)=sum(S(:))/(k^2-k);
  25. end
  26. end