1 ## Copyright (C) 2007-2012 David Bateman
3 ## This file is part of Octave.
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.
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.
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/>.
20 ## @deftypefn {Function File} {} rose (@var{th}, @var{r})
21 ## @deftypefnx {Function File} {} rose (@var{h}, @dots{})
22 ## @deftypefnx {Function File} {@var{h} =} rose (@dots{})
23 ## @deftypefnx {Function File} {[@var{r}, @var{th}] =} rose (@dots{})
25 ## Plot an angular histogram. With one vector argument @var{th}, plots the
26 ## histogram with 20 angular bins. If @var{th} is a matrix, then each column
27 ## of @var{th} produces a separate histogram.
29 ## If @var{r} is given and is a scalar, then the histogram is produced with
30 ## @var{r} bins. If @var{r} is a vector, then the center of each bin are
31 ## defined by the values of @var{r}.
33 ## The optional return value @var{h} is a vector of graphics handles to the
34 ## line objects representing each histogram.
36 ## If two output arguments are requested then, rather than plotting the
37 ## histogram, the polar vectors necessary to plot the histogram are
42 ## [r, t] = rose ([2*randn(1e5,1), pi + 2*randn(1e5,1)]);
47 ## @seealso{polar, compass, hist}
50 function [thout, rout] = rose (varargin)
52 [h, varargin, nargin] = __plt_get_axis_arg__ ((nargout > 1), "rose",
59 ## Force theta to [0,2*pi] range
61 th = atan2 (sin (th), cos (th)) + pi;
66 x = [0.5/x : 1/x : 1] * 2 * pi;
68 ## Force theta to [0,2*pi] range
69 x = atan2 (sin (x), cos (x)) + pi;
72 x = [1/40 : 1/20 : 1] * 2 * pi;
75 [nn, xx] = hist (th, x);
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));
92 hlist = polar (h, th, r);
93 unwind_protect_cleanup
110 %! rose ([2*randn(1e5, 1), pi + 2*randn(1e5, 1)]);