function rosette( varargin )
%function rosette( cax, thetafreq, 'n' )
%function rosette( varargin )
% ROSETTE(cax, THETAFREQ, 'color') where THETAFREQ is a vector with the frequency of each angle
% and the length of the vector THETA provides N, the number of
% angular intervals.
% cax or [] is the specific axis or default axis to be plotted onto
% This function plots the frequency/mass or value in the vector along the
% radial angles [0..90..180..360] in N-intervals
% 'n' is the color to which the lines are to be set
% To do: implement face so the triangles have a faceted "painted" appearance
% Chaitanya A. Athale, 09-06-2006
% $Date: 2006/06/09 14:12:00 $ modified from ROSE.m Clay M. Thompson 7-9-91, The MathWorks, Inc.
if( version == '6.5.0.180913a (R13)')
args = varargin;
nargs = nargin;
cax = [];
if (nargs > 0) && ...
numel(args{1}==1) && ...
ishandle(args(1)) && strcmp(get(args(1),'type'),'axes')
cax = args(1);
args = args(2:end);
nargs = nargs - 1;
end
if( nargs > 1 )
inds = find( strcmpi('parent',args));
if ~isempty(inds)
inds = unique( [inds inds+1] );
pind = inds(end);
if nargs <=pind && ishandle(args(pind))
cax = args(pind);
args(inds) = [];
nargs = length(args);
end
end
end
% END OPTIONS FOR OLD MATLAB VERSIONS: R13 and before
else
[cax,args,nargs] = axescheck(varargin{:});
end
size(args);
thetafreq = args{2};
lcol = args{3}
if isstr(thetafreq)
error('Input arguments must be numeric.');
end
if ~ischar(lcol)
error('Color string must be a charachter');
end
%theta = rem(rem(theta,2*pi)+2*pi,2*pi); % Make sure 0 <= theta <= 2*pi
%%%%%
N = length( thetafreq );
x = (0:N-1)*2*pi/N + pi/N;
%%%old code: sort the array if it has more than one element
%x = sort(rem(x(:)',2*pi));
%%new code: dont sort. take this array as the final values of each
%%interval
if isstr(x) | isstr(thetafreq)
error('Input arguments must be numeric.');
end
% Determine bin edges and get histogram
edges = sort( rem( [ ( x( 2:end ) + x( 1:end-1 ) ) / 2 ( x( end ) + x( 1 ) + 2*pi ) / 2 ], 2*pi ) );
edges = [ edges edges( 1 ) + 2*pi ];
%nn = histc( rem( theta + 2*pi-edges(1),2*pi),edges-edges(1));
%nn(end-1) = nn(end-1)+nn(end);
%nn(end) = [];
nn=thetafreq;
% Form radius values for histogram triangle
if min(size(nn))==1, % Vector
nn = nn(:);
end
[m,n] = size(nn);
mm = 4*m;
r = zeros(mm,n);
r(2:4:mm,:) = nn;
r(3:4:mm,:) = nn;
% Form theta values for histogram triangle from triangle centers (xx)
zz = edges;
t = zeros(mm,1);
t(2:4:mm) = zz(1:m);
t(3:4:mm) = zz(2:m+1);
if ~isempty(cax)
h = polar(cax,t,r,lcol);
else
h = polar(t,r,lcol);
end