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