2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
245
|
19 |
3368
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} stairs (@var{x}, @var{y}) |
|
22 ## Given two vectors of x-y data, bar produces a `stairstep' plot. |
3426
|
23 ## |
2311
|
24 ## If only one argument is given, it is taken as a vector of y-values |
3368
|
25 ## and the x coordinates are taken to be the indices of the elements. |
3426
|
26 ## |
2311
|
27 ## If two output arguments are specified, the data are generated but |
|
28 ## not plotted. For example, |
3426
|
29 ## |
3368
|
30 ## @example |
|
31 ## stairs (x, y); |
|
32 ## @end example |
3426
|
33 ## |
3368
|
34 ## @noindent |
2311
|
35 ## and |
3426
|
36 ## |
3368
|
37 ## @example |
|
38 ## [xs, ys] = stairs (x, y); |
|
39 ## plot (xs, ys); |
|
40 ## @end example |
3426
|
41 ## |
3368
|
42 ## @noindent |
2311
|
43 ## are equivalent. |
3368
|
44 ## @end deftypefn |
5053
|
45 ## |
3407
|
46 ## @seealso{plot, semilogx, semilogy, loglog, polar, mesh, contour, |
5214
|
47 ## bar, replot, xlabel, ylabel, and title} |
4
|
48 |
2314
|
49 ## Author: jwe |
|
50 |
2311
|
51 function [xs, ys] = stairs (x, y) |
4
|
52 |
|
53 |
|
54 if (nargin == 1) |
4030
|
55 if (isvector (x)) |
4
|
56 len = 2 * length (x); |
736
|
57 tmp_xs = tmp_ys = zeros (len, 1); |
4
|
58 k = 0; |
|
59 for i = 1:2:len |
736
|
60 tmp_xs(i) = k++; |
|
61 tmp_ys(i) = x(k); |
|
62 tmp_ys(i+1) = x(k); |
|
63 tmp_xs(i+1) = k; |
4
|
64 endfor |
|
65 else |
|
66 error ("stairs: argument must be a vector"); |
|
67 endif |
|
68 elseif (nargin == 2) |
4030
|
69 if (isvector (x) && isvector (y)) |
4
|
70 xlen = length (x); |
|
71 ylen = length (y); |
|
72 if (xlen == ylen) |
|
73 len = 2 * xlen; |
736
|
74 tmp_xs = tmp_ys = zeros (len, 1); |
3426
|
75 k = 1; |
4
|
76 len_m2 = len - 2; |
3426
|
77 for i = 1:2:len_m2 |
|
78 tmp_xs(i) = x(k); |
|
79 tmp_ys(i) = y(k); |
|
80 tmp_ys(i+1) = y(k); |
4
|
81 k++; |
3426
|
82 tmp_xs(i+1) = x(k); |
4
|
83 if (x(k) < x(k-1)) |
|
84 error ("stairs: x vector values must be in ascending order"); |
|
85 endif |
3426
|
86 endfor |
736
|
87 tmp_xs(len-1) = x(xlen); |
4
|
88 delta = x(xlen) - x(xlen-1); |
736
|
89 tmp_xs(len) = x(xlen) + delta; |
|
90 tmp_ys(len-1) = y(ylen); |
|
91 tmp_ys(len) = y(ylen); |
4
|
92 else |
|
93 error ("stairs: arguments must be the same length"); |
|
94 endif |
|
95 else |
|
96 error ("stairs: arguments must be vectors"); |
|
97 endif |
|
98 else |
904
|
99 usage ("[xs, ys] = stairs (x, y)"); |
4
|
100 endif |
|
101 |
736
|
102 if (nargout == 0) |
|
103 plot (tmp_xs, tmp_ys); |
|
104 else |
|
105 xs = tmp_xs; |
|
106 ys = tmp_ys; |
4
|
107 endif |
|
108 |
|
109 endfunction |