736
|
1 # Copyright (C) 1993, 1994 John W. Eaton |
245
|
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 the |
|
7 # Free Software Foundation; either version 2, or (at your option) any |
|
8 # later version. |
|
9 # |
|
10 # Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # 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, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
18 |
4
|
19 function [xs, ys] = stairs (x, y) |
|
20 |
131
|
21 # usage: [xs, ys] = stairs (x, y) |
4
|
22 # |
131
|
23 # Given two vectors of x-y data, stairs produces a `stairstep' plot. |
4
|
24 # |
|
25 # If only one argument is given, it is taken as a vector of y-values |
|
26 # and the x coordiates are taken to be the indices of the elements. |
|
27 # |
|
28 # If two output arguments are specified, the data are generated but |
|
29 # not plotted. For example, |
|
30 # |
131
|
31 # stairs (x, y); |
4
|
32 # |
|
33 # and |
|
34 # |
|
35 # [xs, ys] = stairs (x, y); |
|
36 # plot (xs, ys); |
|
37 # |
|
38 # are equivalent. |
|
39 # |
|
40 # See also: plot, semilogx, semilogy, loglog, polar, mesh, contour, |
|
41 # bar, gplot, gsplot, replot, xlabel, ylabel, title |
|
42 |
|
43 |
|
44 if (nargin == 1) |
|
45 if (is_vector (x)) |
|
46 len = 2 * length (x); |
736
|
47 tmp_xs = tmp_ys = zeros (len, 1); |
4
|
48 k = 0; |
|
49 for i = 1:2:len |
736
|
50 tmp_xs(i) = k++; |
|
51 tmp_ys(i) = x(k); |
|
52 tmp_ys(i+1) = x(k); |
|
53 tmp_xs(i+1) = k; |
4
|
54 endfor |
|
55 else |
|
56 error ("stairs: argument must be a vector"); |
|
57 endif |
|
58 elseif (nargin == 2) |
|
59 if (is_vector (x) && is_vector (y)) |
|
60 xlen = length (x); |
|
61 ylen = length (y); |
|
62 if (xlen == ylen) |
|
63 len = 2 * xlen; |
736
|
64 tmp_xs = tmp_ys = zeros (len, 1); |
4
|
65 k = 1; |
|
66 len_m2 = len - 2; |
|
67 for i = 1:2:len_m2 |
736
|
68 tmp_xs(i) = x(k); |
|
69 tmp_ys(i) = y(k); |
|
70 tmp_ys(i+1) = y(k); |
4
|
71 k++; |
736
|
72 tmp_xs(i+1) = x(k); |
4
|
73 if (x(k) < x(k-1)) |
|
74 error ("stairs: x vector values must be in ascending order"); |
|
75 endif |
|
76 endfor |
736
|
77 tmp_xs(len-1) = x(xlen); |
4
|
78 delta = x(xlen) - x(xlen-1); |
736
|
79 tmp_xs(len) = x(xlen) + delta; |
|
80 tmp_ys(len-1) = y(ylen); |
|
81 tmp_ys(len) = y(ylen); |
4
|
82 else |
|
83 error ("stairs: arguments must be the same length"); |
|
84 endif |
|
85 else |
|
86 error ("stairs: arguments must be vectors"); |
|
87 endif |
|
88 else |
|
89 error ("usage: [xs, ys] = stairs (x, y)"); |
|
90 endif |
|
91 |
736
|
92 if (nargout == 0) |
|
93 plot (tmp_xs, tmp_ys); |
|
94 else |
|
95 xs = tmp_xs; |
|
96 ys = tmp_ys; |
4
|
97 endif |
|
98 |
|
99 endfunction |