2303
|
1 ### Copyright (C) 1996 John W. Eaton |
|
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 |
|
17 ### Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ### 02111-1307, USA. |
245
|
19 |
2311
|
20 ## usage: [xs, ys] = stairs (x, y) |
|
21 ## |
|
22 ## Given two vectors of x-y data, stairs produces a `stairstep' plot. |
|
23 ## |
|
24 ## If only one argument is given, it is taken as a vector of y-values |
|
25 ## and the x coordiates are taken to be the indices of the elements. |
|
26 ## |
|
27 ## If two output arguments are specified, the data are generated but |
|
28 ## not plotted. For example, |
|
29 ## |
|
30 ## stairs (x, y); |
|
31 ## |
|
32 ## and |
|
33 ## |
|
34 ## [xs, ys] = stairs (x, y); |
|
35 ## plot (xs, ys); |
|
36 ## |
|
37 ## are equivalent. |
|
38 ## |
|
39 ## See also: plot, semilogx, semilogy, loglog, polar, mesh, contour, |
|
40 ## bar, gplot, gsplot, replot, xlabel, ylabel, title |
4
|
41 |
2311
|
42 function [xs, ys] = stairs (x, y) |
4
|
43 |
|
44 |
|
45 if (nargin == 1) |
|
46 if (is_vector (x)) |
|
47 len = 2 * length (x); |
736
|
48 tmp_xs = tmp_ys = zeros (len, 1); |
4
|
49 k = 0; |
|
50 for i = 1:2:len |
736
|
51 tmp_xs(i) = k++; |
|
52 tmp_ys(i) = x(k); |
|
53 tmp_ys(i+1) = x(k); |
|
54 tmp_xs(i+1) = k; |
4
|
55 endfor |
|
56 else |
|
57 error ("stairs: argument must be a vector"); |
|
58 endif |
|
59 elseif (nargin == 2) |
|
60 if (is_vector (x) && is_vector (y)) |
|
61 xlen = length (x); |
|
62 ylen = length (y); |
|
63 if (xlen == ylen) |
|
64 len = 2 * xlen; |
736
|
65 tmp_xs = tmp_ys = zeros (len, 1); |
4
|
66 k = 1; |
|
67 len_m2 = len - 2; |
|
68 for i = 1:2:len_m2 |
736
|
69 tmp_xs(i) = x(k); |
|
70 tmp_ys(i) = y(k); |
|
71 tmp_ys(i+1) = y(k); |
4
|
72 k++; |
736
|
73 tmp_xs(i+1) = x(k); |
4
|
74 if (x(k) < x(k-1)) |
|
75 error ("stairs: x vector values must be in ascending order"); |
|
76 endif |
|
77 endfor |
736
|
78 tmp_xs(len-1) = x(xlen); |
4
|
79 delta = x(xlen) - x(xlen-1); |
736
|
80 tmp_xs(len) = x(xlen) + delta; |
|
81 tmp_ys(len-1) = y(ylen); |
|
82 tmp_ys(len) = y(ylen); |
4
|
83 else |
|
84 error ("stairs: arguments must be the same length"); |
|
85 endif |
|
86 else |
|
87 error ("stairs: arguments must be vectors"); |
|
88 endif |
|
89 else |
904
|
90 usage ("[xs, ys] = stairs (x, y)"); |
4
|
91 endif |
|
92 |
736
|
93 if (nargout == 0) |
|
94 plot (tmp_xs, tmp_ys); |
|
95 else |
|
96 xs = tmp_xs; |
|
97 ys = tmp_ys; |
4
|
98 endif |
|
99 |
|
100 endfunction |