Home > utils > plot > rose_scaled.m

rose_scaled

PURPOSE ^

plots an angle histogram such as the 'rose' function, but accepts scaled values

SYNOPSIS ^

function [histCenters,histRadii] = rose_scaled(varargin)

DESCRIPTION ^

 plots an angle histogram such as the 'rose' function, but accepts scaled values

   ROSE(THETA) plots the angle histogram for the angles in THETA.  
   The angles in the vector THETA must be specified in radians.

   See also ROSE, HIST, POLAR, COMPASS.

   Clay M. Thompson 7-9-91
   Copyright 1984-2005 The MathWorks, Inc.
   $Revision: 5.14.4.4 $  $Date: 2005/04/28 19:56:53 $


   Modified 3/19/2009 Stefan Tomic
     - Accepts different vector strength contributions to the histogram.
     - Added line style functionality and a flag whether or not toplot.
     - The output now is also a list of histogram angle centers
       and radiuses, rather than the line data that the 'rose' function outputs.

   New format is [histCenters,histRadii] = rose_scaled(angles,strengths,lineStyle,do_plot)
     where
       - strengths (optional) is a list of radii that correspond to
         the angles list. Default strength = 1.
       - lineStyle (optional) corresponds the the possible line styles given to
         the plot function. Default is 'b-'
       - do_plot (optional) is a true or false flag that dictates whether or
         not to plot the histogram (default = true)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [histCenters,histRadii] = rose_scaled(varargin)
0002 % plots an angle histogram such as the 'rose' function, but accepts scaled values
0003 %
0004 %   ROSE(THETA) plots the angle histogram for the angles in THETA.
0005 %   The angles in the vector THETA must be specified in radians.
0006 %
0007 %   See also ROSE, HIST, POLAR, COMPASS.
0008 %
0009 %   Clay M. Thompson 7-9-91
0010 %   Copyright 1984-2005 The MathWorks, Inc.
0011 %   $Revision: 5.14.4.4 $  $Date: 2005/04/28 19:56:53 $
0012 %
0013 %
0014 %   Modified 3/19/2009 Stefan Tomic
0015 %     - Accepts different vector strength contributions to the histogram.
0016 %     - Added line style functionality and a flag whether or not toplot.
0017 %     - The output now is also a list of histogram angle centers
0018 %       and radiuses, rather than the line data that the 'rose' function outputs.
0019 %
0020 %   New format is [histCenters,histRadii] = rose_scaled(angles,strengths,lineStyle,do_plot)
0021 %     where
0022 %       - strengths (optional) is a list of radii that correspond to
0023 %         the angles list. Default strength = 1.
0024 %       - lineStyle (optional) corresponds the the possible line styles given to
0025 %         the plot function. Default is 'b-'
0026 %       - do_plot (optional) is a true or false flag that dictates whether or
0027 %         not to plot the histogram (default = true)
0028 
0029 
0030 [cax,args,nargs] = axescheck(varargin{:});
0031 error(nargchk(1,3,nargs,'struct'));
0032 
0033 theta = args{1};
0034 if nargs > 1, 
0035   strengths = args{2}; 
0036 else
0037   strengths = ones(size(theta));
0038 end
0039 if nargs > 2
0040   x = args{3};
0041 end
0042 if nargs > 3
0043   lineStyle = args{4};
0044 else
0045   lineStyle = 'b-';
0046 end
0047 
0048 if nargs > 4
0049   do_plot = args{5};
0050 else
0051   do_plot = 1;
0052 end
0053 
0054 if ischar(theta)
0055   error(id('NonNumericInput'),'Input arguments must be numeric.');
0056 end
0057 theta = rem(rem(theta,2*pi)+2*pi,2*pi); % Make sure 0 <= theta <= 2*pi
0058 if (nargs <= 2),
0059   x = (0:19)*pi/10+pi/20;
0060 
0061 elseif nargs==2,
0062   if ischar(strengths)
0063     error(id('NonNumericInput'),'Input arguments must be numeric.');
0064   end
0065   
0066 elseif nargs==3
0067   if ischar(x)
0068     error(id('NonNumericInput'),'Input arguments must be numeric.');
0069   end
0070 
0071   if length(x)==1,
0072     x = (0:x-1)*2*pi/x + pi/x;
0073   else
0074     x = sort(rem(x(:)',2*pi));
0075   end
0076 
0077 end
0078 if ischar(x) || ischar(theta)
0079   error(id('NonNumericInput'),'Input arguments must be numeric.');
0080 end
0081 
0082 % Determine bin edges and get histogram
0083 edges = sort(rem([(x(2:end)+x(1:end-1))/2 (x(end)+x(1)+2*pi)/2],2*pi));
0084 edges = [edges edges(1)+2*pi];
0085 [dummy,bins] = histc(rem(theta+2*pi-edges(1),2*pi),edges-edges(1));
0086 %nn(end-1) = nn(end-1)+nn(end);
0087 %nn(end) = [];
0088 
0089 nBins = length(x);
0090 for iBin = 1:nBins
0091   nn(iBin) = sum(strengths(bins == iBin));
0092 end
0093 
0094 % Form radius values for histogram triangle
0095 if min(size(nn))==1, % Vector
0096   nn = nn(:); 
0097 end
0098 [m,n] = size(nn);
0099 mm = 4*m;
0100 r = zeros(mm,n);
0101 r(2:4:mm,:) = nn;
0102 r(3:4:mm,:) = nn;
0103 
0104 % Form theta values for histogram triangle from triangle centers (xx)
0105 zz = edges;
0106 
0107 t = zeros(mm,1);
0108 t(2:4:mm) = zz(1:m);
0109 t(3:4:mm) = zz(2:m+1);
0110 
0111 if (do_plot)
0112   if ~isempty(cax)
0113     h = polar(cax,t,r,lineStyle);
0114   else
0115     h = polar(t,r,lineStyle);
0116   end
0117   
0118 end
0119 
0120 histCenters = x;
0121 histRadii = nn;
0122 
0123 function str=id(str)
0124 str = ['MATLAB:rose:' str];

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003