annotate scripts/plot/bar.m @ 2121:bc6ecd8f1175

[project @ 1996-05-12 06:45:55 by jwe]
author jwe
date Sun, 12 May 1996 06:45:55 +0000
parents 5d29638dd524
children 5cffc4b8de57
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1887
5d29638dd524 [project @ 1996-02-06 15:41:33 by jwe]
jwe
parents: 1315
diff changeset
1 # Copyright (C) 1996 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
1315
611d403c7f3d [project @ 1995-06-25 19:56:32 by jwe]
jwe
parents: 1014
diff changeset
17 # Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
245
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 [xb, yb] = bar (x, y)
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
20
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
21 # usage: [xb, yb] = bar (x, y)
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, bar produces a `bar' graph.
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 coordinates 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 #
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
31 # bar (x, y);
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 # [xb, yb] = bar (x, y);
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
36 # plot (xb, yb);
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 # stairs, 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 if (nargin == 1)
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
44 if (is_vector (x))
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
45 len = 3 * length (x) + 1;
736
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
46 tmp_xb = tmp_yb = zeros (len, 1);
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
47 tmp_xb(1) = 0.5;
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
48 tmp_yb(1) = 0;
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
49 k = 1;
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
50 for i = 2:3:len
736
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
51 tmp_xb(i) = k-0.5;
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
52 tmp_xb(i+1) = k+0.5;
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
53 tmp_xb(i+2) = k+0.5;
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
54 tmp_yb(i) = x(k);
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
55 tmp_yb(i+1) = x(k);
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
56 tmp_yb(i+2) = 0.0;
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
57 k++;
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
58 endfor
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
59 else
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
60 error ("bar: argument must be a vector");
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
61 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
62 elseif (nargin == 2)
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
63 if (is_vector (x) && is_vector (y))
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
64 xlen = length (x);
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
65 ylen = length (y);
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
66 if (xlen == ylen)
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
67 len = 3 * xlen + 1;
736
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
68 tmp_xb = tmp_yb = zeros (len, 1);
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
69 delta = (x(2) - x(1)) / 2.0;
736
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
70 tmp_xb(1) = x(1) - delta;
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
71 tmp_yb(1) = 0.0;
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
72 k = 1;
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
73 for i = 2:3:len
736
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
74 tmp_xb(i) = tmp_xb(i-1);
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
75 tmp_xb(i+1) = tmp_xb(i) + 2.0 * delta;
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
76 tmp_xb(i+2) = tmp_xb(i+1);
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
77 tmp_yb(i) = y(k);
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
78 tmp_yb(i+1) = y(k);
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
79 tmp_yb(i+2) = 0.0;
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
80 if (k < xlen)
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
81 delta = (x(k+1) - x(k)) / 2.0;
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
82 if (x(k+1) < x(k))
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
83 error ("bar: x vector values must be in ascending order");
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 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
86 k++;
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
87 endfor
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 ("bar: arguments must be the same length");
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 else
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
92 error ("bar: arguments must be vectors");
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
93 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
94 else
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 736
diff changeset
95 usage ("[xb, yb] = bar (x, y)");
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
96 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
97
736
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
98 if (nargout == 0)
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
99 plot (tmp_xb, tmp_yb);
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
100 else
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
101 xb = tmp_xb;
c8f88bd3202b [project @ 1994-09-24 03:28:05 by jwe]
jwe
parents: 245
diff changeset
102 yb = tmp_yb;
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
103 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
104
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
105 endfunction