adjacency_plot_und.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. function [X,Y,Z] = adjacency_plot_und(aij,coor)
  2. %ADJACENCY_PLOT_UND Quick visualization tool
  3. %
  4. % [X,Y,Z] = ADJACENCY_PLOT(AIJ,COOR) takes adjacency matrix AIJ and node
  5. % spatial coordinates COOR and generates three vectors that can be used
  6. % for quickly plotting the edges in AIJ. If no coordinates are specified,
  7. % then each node is assigned a position on a circle. COOR can, in
  8. % general, be 2D or 3D.
  9. %
  10. % Example:
  11. %
  12. % >> load AIJ; % load your adjacency matrix
  13. % >> load COOR; % load 3D coordinates for each node
  14. % >> [x,y,z] = adjacency_plot_und(AIJ,COOR); % call function
  15. % >> plot3(x,y,z); % plots network as a single line object
  16. %
  17. % If COOR were 2D, the PLOT3 command changes to a PLOT command.
  18. %
  19. % NOTE: This function is similar to MATLAB's GPLOT command.
  20. %
  21. % Richard Betzel, Indiana University, 2013
  22. n = length(aij);
  23. if nargin < 2
  24. coor = zeros(n,2);
  25. for i = 1:n
  26. coor(i,:) = [cos(2*pi*(i - 1)./n), sin(2*pi*(i - 1)./n)];
  27. end
  28. end
  29. [i,j] = find(triu(aij,1));
  30. [~, p] = sort(max(i,j));
  31. i = i(p);
  32. j = j(p);
  33. X = [ coor(i,1) coor(j,1)]';
  34. Y = [ coor(i,2) coor(j,2)]';
  35. if size(coor,2) == 3
  36. Z = [ coor(i,3) coor(j,3)]';
  37. end
  38. if isfloat(coor) || nargout ~= 0
  39. X = [X; NaN(size(i))'];
  40. Y = [Y; NaN(size(i))'];
  41. if size(coor,2) == 3
  42. Z = [Z; NaN(size(i))'];
  43. end
  44. end
  45. X = X(:);
  46. Y = Y(:);
  47. if size(coor,2) == 3
  48. Z = Z(:);
  49. end