home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l450 / 1.ddi / MATPAK.1 / arc / BAR.M < prev    next >
Encoding:
Text File  |  1989-01-18  |  890 b   |  37 lines

  1. function [xo,yo] = bar(x,y)
  2. %BAR    Bar graph.
  3. %    BAR(Y) draws a bar graph of the elements of vector Y.
  4. %    BAR(X,Y) draws a bar graph of the elements in vector Y at
  5. %    the locations specified in X.  The X-values must be in
  6. %    ascending order and evenly spaced.
  7. %    [XX,YY] = BAR(X,Y) does not draw a graph, but returns vectors
  8. %    X and Y such that PLOT(XX,YY) is the bar chart.
  9. %    See also STAIRS and HIST.
  10.  
  11. %    C.B Moler 2-06-86
  12. %    Modified 24-Dec-88, LS.
  13. %    Copyright (c) 1985-88 by the MathWorks, Inc.
  14.                
  15. n = length(x);
  16. if nargin == 1
  17.     y = x;
  18.     x = 1:n;
  19. end
  20. delta = (max(x) - min(x)) / (n-1);
  21. nn = 3*n;
  22. yy = zeros(nn+1,1);
  23. xx = yy;
  24. t = x(:)' - 0.5*delta;
  25. xx(1:3:nn) = t;
  26. xx(2:3:nn) = t;
  27. xx(3:3:nn) = t + delta;
  28. yy(2:3:nn) = y;
  29. yy(3:3:nn) = y;
  30. xx(nn+1) = xx(nn);
  31. if nargout == 0
  32.     plot(xx,yy,[xx(1) xx(length(xx))],[0 0],'-')
  33. else
  34.     xo = xx;
  35.     yo = yy;
  36. end
  37.