2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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 |
3368
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} bar (@var{x}, @var{y}) |
|
22 ## Given two vectors of x-y data, @code{bar} produces a bar graph. |
3426
|
23 ## |
2311
|
24 ## If only one argument is given, it is taken as a vector of y-values |
|
25 ## and the x coordinates are taken to be the indices of the elements. |
3426
|
26 ## |
2311
|
27 ## If two output arguments are specified, the data are generated but |
|
28 ## not plotted. For example, |
3426
|
29 ## |
3368
|
30 ## @example |
|
31 ## bar (x, y); |
|
32 ## @end example |
3426
|
33 ## |
3368
|
34 ## @noindent |
2311
|
35 ## and |
3426
|
36 ## |
3368
|
37 ## @example |
|
38 ## [xb, yb] = bar (x, y); |
|
39 ## plot (xb, yb); |
|
40 ## @end example |
3426
|
41 ## |
3368
|
42 ## @noindent |
2311
|
43 ## are equivalent. |
3368
|
44 ## @end deftypefn |
3407
|
45 ## @seealso{plot, semilogx, semilogy, loglog, polar, mesh, contour, |
3408
|
46 ## stairs, gplot, gsplot, replot, xlabel, ylabel, and title} |
4
|
47 |
2314
|
48 ## Author: jwe |
|
49 |
2311
|
50 function [xb, yb] = bar (x, y) |
4
|
51 |
|
52 if (nargin == 1) |
4030
|
53 if (isvector (x)) |
4
|
54 len = 3 * length (x) + 1; |
736
|
55 tmp_xb = tmp_yb = zeros (len, 1); |
|
56 tmp_xb(1) = 0.5; |
|
57 tmp_yb(1) = 0; |
4
|
58 k = 1; |
|
59 for i = 2:3:len |
736
|
60 tmp_xb(i) = k-0.5; |
|
61 tmp_xb(i+1) = k+0.5; |
|
62 tmp_xb(i+2) = k+0.5; |
|
63 tmp_yb(i) = x(k); |
|
64 tmp_yb(i+1) = x(k); |
|
65 tmp_yb(i+2) = 0.0; |
4
|
66 k++; |
|
67 endfor |
|
68 else |
|
69 error ("bar: argument must be a vector"); |
|
70 endif |
|
71 elseif (nargin == 2) |
4030
|
72 if (isvector (x) && isvector (y)) |
4
|
73 xlen = length (x); |
|
74 ylen = length (y); |
|
75 if (xlen == ylen) |
|
76 len = 3 * xlen + 1; |
736
|
77 tmp_xb = tmp_yb = zeros (len, 1); |
4723
|
78 cutoff = zeros (1, xlen); |
3260
|
79 for i = 1:xlen-1 |
|
80 cutoff(i) = (x(i) + x(i+1)) / 2.0; |
|
81 endfor |
|
82 delta_p = cutoff(1) - x(1); |
|
83 delta_m = delta_p; |
|
84 tmp_xb(1) = x(1) - delta_m; |
736
|
85 tmp_yb(1) = 0.0; |
3426
|
86 k = 1; |
4
|
87 for i = 2:3:len |
736
|
88 tmp_xb(i) = tmp_xb(i-1); |
3260
|
89 tmp_xb(i+1) = x(k) + delta_p; |
736
|
90 tmp_xb(i+2) = tmp_xb(i+1); |
3426
|
91 tmp_yb(i) = y(k); |
|
92 tmp_yb(i+1) = y(k); |
|
93 tmp_yb(i+2) = 0.0; |
4
|
94 if (k < xlen) |
|
95 if (x(k+1) < x(k)) |
|
96 error ("bar: x vector values must be in ascending order"); |
|
97 endif |
3426
|
98 delta_m = x(k+1) - cutoff(k); |
3260
|
99 k++; |
|
100 if (k < xlen) |
|
101 delta_p = cutoff(k) - x(k); |
3426
|
102 else |
|
103 delta_p = delta_m; |
3260
|
104 endif |
3426
|
105 endif |
|
106 endfor |
4
|
107 else |
|
108 error ("bar: arguments must be the same length"); |
|
109 endif |
|
110 else |
|
111 error ("bar: arguments must be vectors"); |
|
112 endif |
|
113 else |
904
|
114 usage ("[xb, yb] = bar (x, y)"); |
4
|
115 endif |
|
116 |
736
|
117 if (nargout == 0) |
|
118 plot (tmp_xb, tmp_yb); |
|
119 else |
|
120 xb = tmp_xb; |
|
121 yb = tmp_yb; |
4
|
122 endif |
|
123 |
|
124 endfunction |