home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / SPARFUN.DI$ / GPLOT.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  1.4 KB  |  50 lines

  1. function [Xout,Yout]=gplot(A,xy,lc)
  2. %GPLOT     Plot a "graph theoretic" graph.
  3. %    GPLOT(A,xy) plots the graph specified by A and xy.
  4. %    A graph, G, is a set of nodes numbered from 1 to n,
  5. %    and a set of connections, or edges, between them.
  6. %    In order to plot G, two matrices are needed.
  7. %    The adjacency matrix, A, has a(i,j) nonzero if and
  8. %    only if node i is connected to node j.  The coordinates
  9. %    array, xy, is an n-by-2 matrix with the position for
  10. %    node i in the i-th row, xy(i,:) = [x(i) y(i)].
  11. %    
  12. %    GPLOT(A,xy,lc) uses line type and color instead of the 
  13. %    default, 'r-'.   For example, lc = 'g:'.  See PLOT.
  14. %
  15. %    [X,Y] = GPLOT(A,xy) returns the NaN-punctuated vectors
  16. %    X and Y without actually generating a plot. These vectors
  17. %    can be used to generate the plot at a later    time if desired.
  18. %    
  19. %    See also SPY, TREEPLOT, SUBMESH, UNMESH.
  20.  
  21. %    John Gilbert, 1991.
  22. %    Modified 1-21-91, LS; 2-28-92, 6-16-92 CBM.
  23. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  24.  
  25. if nargin < 3, 
  26.     lc = 'r-';
  27. end;
  28.  
  29. [i,j] = find(A);
  30. [ignore, p] = sort(max(i,j));
  31. i = i(p);
  32. j = j(p);
  33.  
  34. % Create a long, NaN-seperated list of line segments,
  35. % rather than individual segments.
  36.  
  37. X = [ xy(i,1) xy(j,1) NaN*ones(size(i))]';
  38. Y = [ xy(i,2) xy(j,2) NaN*ones(size(i))]';
  39. X = X(:);
  40. Y = Y(:);
  41.  
  42. if nargout==0,
  43.     plot(X, Y, lc);
  44.     % Use RETURN to suppress the output
  45.     return;
  46. end;
  47.  
  48. Xout = X;
  49. Yout = Y;
  50.