annotate scripts/plot/stairs.m @ 736:c8f88bd3202b

[project @ 1994-09-24 03:28:05 by jwe]
author jwe
date Sat, 24 Sep 1994 03:29:38 +0000
parents 16a24e76d6e0
children 3470f1e25a79
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
736
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
1 # Copyright (C) 1993, 1994 John W. Eaton
245
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 131
diff changeset
2 #
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 131
diff changeset
3 # This file is part of Octave.
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 131
diff changeset
4 #
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 131
diff changeset
5 # Octave is free software; you can redistribute it and/or modify it
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 131
diff changeset
6 # under the terms of the GNU General Public License as published by the
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 131
diff changeset
7 # Free Software Foundation; either version 2, or (at your option) any
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 131
diff changeset
8 # later version.
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 131
diff changeset
9 #
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 131
diff changeset
10 # Octave is distributed in the hope that it will be useful, but WITHOUT
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 131
diff changeset
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 131
diff changeset
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 131
diff changeset
13 # for more details.
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 131
diff changeset
14 #
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 131
diff changeset
15 # You should have received a copy of the GNU General Public License
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 131
diff changeset
16 # along with Octave; see the file COPYING. If not, write to the Free
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 131
diff changeset
17 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 131
diff changeset
18
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
19 function [xs, ys] = stairs (x, y)
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
20
131
5b46fbec1488 [project @ 1993-09-28 14:23:43 by jwe]
jwe
parents: 4
diff changeset
21 # usage: [xs, ys] = stairs (x, y)
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
22 #
131
5b46fbec1488 [project @ 1993-09-28 14:23:43 by jwe]
jwe
parents: 4
diff changeset
23 # Given two vectors of x-y data, stairs produces a `stairstep' plot.
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
24 #
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
25 # If only one argument is given, it is taken as a vector of y-values
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
26 # and the x coordiates are taken to be the indices of the elements.
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
27 #
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
28 # If two output arguments are specified, the data are generated but
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
29 # not plotted. For example,
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
30 #
131
5b46fbec1488 [project @ 1993-09-28 14:23:43 by jwe]
jwe
parents: 4
diff changeset
31 # stairs (x, y);
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
32 #
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
33 # and
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
34 #
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
35 # [xs, ys] = stairs (x, y);
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
36 # plot (xs, ys);
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
37 #
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
38 # are equivalent.
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
39 #
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
40 # See also: plot, semilogx, semilogy, loglog, polar, mesh, contour,
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
41 # bar, gplot, gsplot, replot, xlabel, ylabel, title
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
42
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
43
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
44 if (nargin == 1)
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
45 if (is_vector (x))
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
46 len = 2 * length (x);
736
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
47 tmp_xs = tmp_ys = zeros (len, 1);
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
48 k = 0;
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
49 for i = 1:2:len
736
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
50 tmp_xs(i) = k++;
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
51 tmp_ys(i) = x(k);
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
52 tmp_ys(i+1) = x(k);
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
53 tmp_xs(i+1) = k;
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
54 endfor
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
55 else
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
56 error ("stairs: argument must be a vector");
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
57 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
58 elseif (nargin == 2)
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
59 if (is_vector (x) && is_vector (y))
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
60 xlen = length (x);
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
61 ylen = length (y);
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
62 if (xlen == ylen)
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
63 len = 2 * xlen;
736
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
64 tmp_xs = tmp_ys = zeros (len, 1);
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
65 k = 1;
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
66 len_m2 = len - 2;
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
67 for i = 1:2:len_m2
736
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
68 tmp_xs(i) = x(k);
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
69 tmp_ys(i) = y(k);
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
70 tmp_ys(i+1) = y(k);
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
71 k++;
736
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
72 tmp_xs(i+1) = x(k);
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
73 if (x(k) < x(k-1))
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
74 error ("stairs: x vector values must be in ascending order");
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
75 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
76 endfor
736
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
77 tmp_xs(len-1) = x(xlen);
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
78 delta = x(xlen) - x(xlen-1);
736
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
79 tmp_xs(len) = x(xlen) + delta;
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
80 tmp_ys(len-1) = y(ylen);
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
81 tmp_ys(len) = y(ylen);
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
82 else
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
83 error ("stairs: arguments must be the same length");
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
84 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
85 else
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
86 error ("stairs: arguments must be vectors");
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
87 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
88 else
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
89 error ("usage: [xs, ys] = stairs (x, y)");
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
90 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
91
736
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
92 if (nargout == 0)
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
93 plot (tmp_xs, tmp_ys);
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
94 else
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
95 xs = tmp_xs;
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
96 ys = tmp_ys;
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
97 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
98
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
99 endfunction