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 |
2311
|
20 ## usage: [xb, yb] = bar (x, y) |
|
21 ## |
|
22 ## Given two vectors of x-y data, bar produces a `bar' graph. |
|
23 ## |
|
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. |
|
26 ## |
|
27 ## If two output arguments are specified, the data are generated but |
|
28 ## not plotted. For example, |
|
29 ## |
|
30 ## bar (x, y); |
|
31 ## |
|
32 ## and |
|
33 ## |
|
34 ## [xb, yb] = bar (x, y); |
|
35 ## plot (xb, yb); |
|
36 ## |
|
37 ## are equivalent. |
|
38 ## |
|
39 ## See also: plot, semilogx, semilogy, loglog, polar, mesh, contour, |
2325
|
40 ## stairs, gplot, gsplot, replot, xlabel, ylabel, title |
4
|
41 |
2314
|
42 ## Author: jwe |
|
43 |
2311
|
44 function [xb, yb] = bar (x, y) |
4
|
45 |
|
46 if (nargin == 1) |
|
47 if (is_vector (x)) |
|
48 len = 3 * length (x) + 1; |
736
|
49 tmp_xb = tmp_yb = zeros (len, 1); |
|
50 tmp_xb(1) = 0.5; |
|
51 tmp_yb(1) = 0; |
4
|
52 k = 1; |
|
53 for i = 2:3:len |
736
|
54 tmp_xb(i) = k-0.5; |
|
55 tmp_xb(i+1) = k+0.5; |
|
56 tmp_xb(i+2) = k+0.5; |
|
57 tmp_yb(i) = x(k); |
|
58 tmp_yb(i+1) = x(k); |
|
59 tmp_yb(i+2) = 0.0; |
4
|
60 k++; |
|
61 endfor |
|
62 else |
|
63 error ("bar: argument must be a vector"); |
|
64 endif |
|
65 elseif (nargin == 2) |
|
66 if (is_vector (x) && is_vector (y)) |
|
67 xlen = length (x); |
|
68 ylen = length (y); |
|
69 if (xlen == ylen) |
|
70 len = 3 * xlen + 1; |
736
|
71 tmp_xb = tmp_yb = zeros (len, 1); |
3260
|
72 cutoff = zeros (1, xlen-1); |
|
73 for i = 1:xlen-1 |
|
74 cutoff(i) = (x(i) + x(i+1)) / 2.0; |
|
75 endfor |
|
76 delta_p = cutoff(1) - x(1); |
|
77 delta_m = delta_p; |
|
78 tmp_xb(1) = x(1) - delta_m; |
736
|
79 tmp_yb(1) = 0.0; |
4
|
80 k = 1; |
|
81 for i = 2:3:len |
736
|
82 tmp_xb(i) = tmp_xb(i-1); |
3260
|
83 tmp_xb(i+1) = x(k) + delta_p; |
736
|
84 tmp_xb(i+2) = tmp_xb(i+1); |
|
85 tmp_yb(i) = y(k); |
|
86 tmp_yb(i+1) = y(k); |
|
87 tmp_yb(i+2) = 0.0; |
4
|
88 if (k < xlen) |
|
89 if (x(k+1) < x(k)) |
|
90 error ("bar: x vector values must be in ascending order"); |
|
91 endif |
3260
|
92 delta_m = x(k+1) - cutoff(k); |
|
93 k++; |
|
94 if (k < xlen) |
|
95 delta_p = cutoff(k) - x(k); |
|
96 else |
|
97 delta_p = delta_m; |
|
98 endif |
|
99 endif |
4
|
100 endfor |
|
101 else |
|
102 error ("bar: arguments must be the same length"); |
|
103 endif |
|
104 else |
|
105 error ("bar: arguments must be vectors"); |
|
106 endif |
|
107 else |
904
|
108 usage ("[xb, yb] = bar (x, y)"); |
4
|
109 endif |
|
110 |
736
|
111 if (nargout == 0) |
|
112 plot (tmp_xb, tmp_yb); |
|
113 else |
|
114 xb = tmp_xb; |
|
115 yb = tmp_yb; |
4
|
116 endif |
|
117 |
|
118 endfunction |