strengths_und_sign.m 947 B

123456789101112131415161718192021222324252627282930
  1. function [Spos,Sneg,vpos,vneg] = strengths_und_sign(W)
  2. %STRENGTHS_UND_SIGN Strength and weight
  3. %
  4. % [Spos Sneg] = strengths_und_sign(W);
  5. % [Spos Sneg vpos vneg] = strengths_und_sign(W);
  6. %
  7. % Node strength is the sum of weights of links connected to the node.
  8. %
  9. % Inputs: W, undirected connection matrix with positive
  10. % and negative weights
  11. %
  12. % Output: Spos/Sneg, nodal strength of positive/negative weights
  13. % vpos/vneg, total positive/negative weight
  14. %
  15. %
  16. % 2011, Mika Rubinov, UNSW
  17. % Modification History:
  18. % Mar 2011: Original
  19. n = length(W); %number of nodes
  20. W(1:n+1:end) = 0; %clear diagonal
  21. Spos = sum( W.*(W>0)); %positive strengths
  22. Sneg = sum(-W.*(W<0)); %negative strengths
  23. if nargout>2
  24. vpos = sum(Spos); %positive weight
  25. vneg = sum(Sneg); %negative weight
  26. end