Mercurial > hg > octave-lyh
annotate scripts/plot/rose.m @ 14335:ce2b59a6d0e5
maint: periodic merge of stable to default.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 05 Feb 2012 15:32:24 -0800 |
parents | 11949c9795a0 4d917a6a858b |
children | c2dbdeaa25df |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14092
diff
changeset
|
1 ## Copyright (C) 2007-2012 David Bateman |
7322 | 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 3 of the License, or (at | |
8 ## your option) 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, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {} rose (@var{th}, @var{r}) |
7322 | 21 ## @deftypefnx {Function File} {} rose (@var{h}, @dots{}) |
7710 | 22 ## @deftypefnx {Function File} {@var{h} =} rose (@dots{}) |
23 ## @deftypefnx {Function File} {[@var{r}, @var{th}] =} rose (@dots{}) | |
7322 | 24 ## |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
25 ## Plot an angular histogram. With one vector argument @var{th}, plots the |
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
26 ## histogram with 20 angular bins. If @var{th} is a matrix, then each column |
7322 | 27 ## of @var{th} produces a separate histogram. |
28 ## | |
29 ## If @var{r} is given and is a scalar, then the histogram is produced with | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
30 ## @var{r} bins. If @var{r} is a vector, then the center of each bin are |
7322 | 31 ## defined by the values of @var{r}. |
32 ## | |
14001
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
33 ## The optional return value @var{h} is a vector of graphics handles to the |
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
34 ## line objects representing each histogram. |
7322 | 35 ## |
14001
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
36 ## If two output arguments are requested then, rather than plotting the |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
37 ## histogram, the polar vectors necessary to plot the histogram are |
7322 | 38 ## returned. |
7710 | 39 ## |
7322 | 40 ## @example |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
41 ## @group |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
42 ## [r, t] = rose ([2*randn(1e5,1), pi + 2*randn(1e5,1)]); |
7322 | 43 ## polar (r, t); |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
44 ## @end group |
7322 | 45 ## @end example |
46 ## | |
14001
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
47 ## @seealso{polar, compass, hist} |
7322 | 48 ## @end deftypefn |
49 | |
50 function [thout, rout] = rose (varargin) | |
51 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
52 [h, varargin, nargin] = __plt_get_axis_arg__ ((nargout > 1), "rose", |
10549 | 53 varargin{:}); |
7322 | 54 |
55 if (nargin < 1) | |
56 print_usage (); | |
57 endif | |
58 | |
59 ## Force theta to [0,2*pi] range | |
60 th = varargin {1}; | |
61 th = atan2 (sin (th), cos (th)) + pi; | |
62 | |
63 if (nargin > 1) | |
64 x = varargin {2}; | |
65 if (isscalar (x)) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
66 x = [0.5/x : 1/x : 1] * 2 * pi; |
7322 | 67 else |
68 ## Force theta to [0,2*pi] range | |
69 x = atan2 (sin (x), cos (x)) + pi; | |
70 endif | |
71 else | |
72 x = [1/40 : 1/20 : 1] * 2 * pi; | |
73 endif | |
74 | |
75 [nn, xx] = hist (th, x); | |
76 xx = xx(:).'; | |
77 if (isvector (nn)) | |
78 nn = nn (:); | |
79 endif | |
80 x1 = xx(1:end-1) + diff (xx, 1) / 2; | |
81 x1 = [x1 ; x1; x1; x1](:); | |
82 th = [0; 0; x1; 2*pi ; 2*pi]; | |
83 r = zeros (4 * size (nn, 1), size (nn, 2)); | |
84 r(2:4:end, :) = nn; | |
85 r(3:4:end, :) = nn; | |
86 | |
87 if (nargout < 2) | |
88 oldh = gca (); | |
89 unwind_protect | |
90 axes (h); | |
91 newplot (); | |
92 hlist = polar (h, th, r); | |
93 unwind_protect_cleanup | |
94 axes (oldh); | |
95 end_unwind_protect | |
96 | |
97 if (nargout > 0) | |
98 thout = hlist; | |
99 endif | |
100 else | |
101 thout = th; | |
102 rout = r; | |
103 endif | |
104 | |
105 endfunction | |
106 | |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
107 |
7322 | 108 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
109 %! clf; |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
110 %! rose ([2*randn(1e5, 1), pi + 2*randn(1e5, 1)]); |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
111 |