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

  1. function [xo,yo] = stairs(x,y)
  2. %STAIRS    Stairstep graph (bar graph without internal lines).
  3. %    Stairstep plots are useful for drawing time history plots of
  4. %    digital sampled-data systems.
  5. %    STAIRS(Y) draws a stairstep graph of the elements of vector Y.
  6. %    STAIRS(X,Y) draws a stairstep graph of the elements in vector Y at
  7. %    the locations specified in X.  The X-values must be in
  8. %    ascending order and evenly spaced.
  9. %    [XX,YY] = STAIRS(X,Y) does not draw a graph, but returns vectors
  10. %    X and Y such that PLOT(XX,YY) is the stairstep graph.
  11. %
  12. %    See also BAR, HIST.
  13.  
  14. %    L. Shure, 12-22-88.
  15. %    Revised A.Grace and C.Thompson 8-22-90.
  16. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  17.  
  18. [n,nx] = size(x); 
  19. if isstr(x)
  20.     error('Input arguments must be numeric.')
  21. end
  22. if min(n,nx) > 1
  23.     error('Input arguments must be vectors.')
  24. end
  25.  
  26. % Transpose x if row vector
  27. if (n == 1 & nx > 1), x = x.'; end 
  28.  
  29. [n,nx] = size(x); 
  30. if nargin==1, y=x; x=[0:n-1]'; end 
  31. if isstr(y)
  32.     error('Input arguments must be numeric.')
  33. end
  34.  
  35. [n,nc] = size(y); 
  36.  
  37. % Transpose x if row vector
  38. if (n == 1 & nc > 1), y = y.'; [n,nc] = size(y); end 
  39.  
  40. if (nx ~= nc & nx~= 1 & nc ~= 1)
  41.     error('Vectors must have the same number of columns')
  42. end
  43.  
  44. y2 = [];
  45. for i=1:nc 
  46.     y1 = [ y(:,i).'; y(:,i).'];
  47.     y2 = [y2, y1(:)];
  48. end
  49.  
  50.  
  51. x2 = [];
  52. for i=1:nx 
  53.     x1 = [ x(:,i).'; x(:,i).'];
  54.     x2 = [x2, x1(:)];
  55. end
  56. % Remove extraneous first point
  57. x2(1,:) = [];
  58.  
  59. % Uncomment next line if you want last point to be flat
  60. %x2 = [x2; 2*x2(2*n-1,:)-x2(2*n-3,:)];
  61. % ... and comment out the next line. 
  62. y2(2*n,:) = [];
  63.  
  64. if (nargout == 0)
  65.     plot(x2,y2);
  66. else
  67.     xo = x2; 
  68.     yo = y2;
  69. end
  70.