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

  1. function treeplot(p,c,d)
  2. %TREEPLOT Plot a picture of a tree.
  3. %    TREEPLOT(p,c,d)
  4. %        p is a vector of parent pointers, with p(i) == 0 for a root.
  5. %        c is a color and character for nodes, or '' to not plot nodes.
  6. %        d is a color and character for edges, or '' to not plot edges.
  7. %        c or d may be omitted, and reasonable defaults are used.
  8. %
  9. %    See also ETREE, TREELAYOUT, ETREEPLOT.
  10.  
  11. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  12.  
  13. [x,y,h]=treelayout(p);
  14. f = find(p~=0);
  15. pp = p(f);
  16. X = [x(f); x(pp); NaN*ones(size(f))];
  17. Y = [y(f); y(pp); NaN*ones(size(f))];
  18. X = X(:);
  19. Y = Y(:);
  20.  
  21. if nargin == 1,
  22.     n = max(size(p));
  23.     if n < 500,
  24.         plot (x, y, 'ro', X, Y, 'r-');
  25.     else,
  26.         plot (X, Y, 'r-');
  27.     end;
  28. else,
  29.         [ignore, clen] = size(c);
  30.         if nargin < 3, 
  31.         if clen > 1, 
  32.             d = [c(1:clen-1) '-']; 
  33.         else,
  34.             d = 'r-';
  35.         end;
  36.     end;
  37.     [ignore, dlen] = size(d);
  38.     if clen>0 & dlen>0
  39.         plot (x, y, c, X, Y, d);
  40.     elseif clen>0,
  41.         plot (x, y, c);
  42.     elseif dlen>0,
  43.         plot (X, Y, d);
  44.     else
  45.     end;
  46. end;
  47. xlabel(['height = ' int2str(h)]);
  48. axis([0 1 0 1]);
  49.