function out=mmpolar(varargin)
%MMPOLAR Polar Plot with Settable Properties.
% MMPOLAR(Theta,Rho) creates a polar coordinate plot using the angle Theta
% in RADIANS and radius in Rho. Rho can contain negative values.
% MMPOLAR(Theta,Rho,S) creates the plot using the line spec given by S. See
% the function PLOT for information about S.
% MMPOLAR(Theta1,Rho1,S1,Theta2,Rho2,S2,...) plots all the defined curves.
%
% MMPOLAR(Theta1,Rho1,S1,...,'PName',PValue,...) plots all defined curves,
% and sets plot property names to the corresponding property values.
% MMPOLAR(Theta1,Rho1,S1,...,P) plots all the defined curves, and uses the
% structure P having fieldnames equal to plot property names to set
% corresponding property values contained in the associated fields.
%
% H=MMPOLAR(Theta,Rho,...) returns handles to lines or lineseries objects.
% For example, set(H,'LineWidth',2) sets all linewidths to 2 points.
% Note: 'LineWidth' is NOT a property that can be set with MMPOLAR. It must
% be set as shown above by using the SET function on the line handles H.
%
% MMPOLAR('PName',PValue,...) sets the property names to the corresponding
% property values. See below for property name/value pairs. Just as with
% the function SET 'PName' is case insensitive and need only be unique.
% MMPOLAR with no input argument returns a structure with fieldnames equal
% to property names each containing the associated property values.
% MMPOLAR(P) sets property values using the structure P as described above.
% MMPOLAR('PName') returns the property value associated with 'PName'.
% MMPOLAR({'PName1','PName2',...}) returns multiple property values in a
% cell array.
% MMPOLAR(Hax,...) uses the axes having handle Hax.
%
% Examples: MMPOLAR(Theta,Rho,S,'Style','compass') creates a polar plot with
% theta=0 pointing North and theta increasing in the clockwise direction.
%
% MMPOLAR(Theta,Rho,S) creates a cartesian polar plot where theta=0 is along
% the x-axis and theta increases in the counterclockwise direction.
%
% MMPOLAR works with HOLD, XLABEL, YLABEL, TITLE, ZOOM, SUBPLOT
% but does not work with AXIS, GRID (Use MMPOLAR properties to set these)
%
% See also POLAR, PLOT, HOLD
%
% PROPERTY VALUE {Default} DESCRIPTION
% Style {cartesian} | compass shortcut to two common polar
% styles. Cartesian: theta=0 points east and increases
% going north. Compass: theta=0 points north and
% increases going east. See TDirection and TZeroDirection.
% Axis {on} | off shortcut for grids, ticks, border,
% backgroundcolor, visibility
% Border {on} | off shortcut for axis border, tick mark visibility.
% Grid {on} | off shortcut for visibility of rho and theta grids
% RLimit [Rmin Rmax] rho axis limits, may be negative values
% TLimit [Tmin Tmax] theta axis limits in RADIANS
% RTickUnits {''} string added to last rho tick label to denote units
% TTickScale {degrees} | radians theta axis tick label scaling
% TDirection cw | {ccw} direction of increasing theta
% TZeroDirection North | {East} | South | West theta=0 axis direction
%
% BackgroundColor {w} colorspec for axis background color
% BorderColor {k} colorspec for axis border and tick mark colors
% FontName string font name for tick labels
% FontSize scalar font size for tick labels
% FontWeight {normal} | bold font weight for tick labels
% TickLength {.02} normalized length of rho and theta axis tick marks
%
% RGridColor {k} colorspec for rho axis grid color
% RGridLineStyle - | -- | {:} | -. rho axis grid line style
% RGridLineWidth {0.5} rho axis grid line width in points
% RGridVisible {on} | off rho axis grid visibility
% RTickAngle [scalar] angular position of rho axis tick labels in
% TTickScale units
% RTickOffset {.04} Normalized radial offset for rho tick labels
% RTickLabel string cell array containing rho axis tick labels
% RTickLabelVisible {on} | off visibility of rho axis tick labels
% RTickLabelHalign {center} | left | right horizontal
% alignment of rho axis tick labels
% RTickLabelValign {middle} | top | cap | baseline | bottom vertical
% alignment of rho axis tick labels
% RTickValue [vector] vector containing rho axis tick positions
% RTickVisible {on} | off rho axis tick visibility
%
% TGridColor colorspec for theta axis grid color
% TGridLineStyle - | -- | {:} | -. theta axis grid line style
% TGridLineWidth {0.5} theta axis grid line width in points
% TGridVisible {on} | off theta axis grid visibility
% TTickDelta theta axis tick spacing in TTickScale units
% {15 degrees or pi/12 radians}
% TTickDirection {in} | out direction of theta tick marks
% TTickOffset {.08} normalized radial offset of theta tick labels
% TTickLabel string cell array containing theta axis tick labels
% TTickLabelVisible {on} | off visiblity of theta axis tick labels
% TTickSign {+-} | + sign of theta tick labels
% TTickValue [vector] vector of theta ticks in TTickScale units
% TTickVisible {on} | off theta axis tick visibility
% D.C. Hanselman, University of Maine, Orono, ME 04469
% MasteringMatlab@yahoo.com
% Mastering MATLAB 7
% 2005-04-25, 2006-01-18, 2006-04-06, 2006-05-17, 2006-05-18
% 2006-10-03, 2007-03-04, 2008-03-18
%--------------------------------------------------------------------------
% Parse Inputs Parse Inputs
%--------------------------------------------------------------------------
% Find MMPOLAR axes if it exists
nargi=nargin;
% find MMPOLAR axes if it is supplied or if it is the current axes
if nargi>0 && isscalar(varargin{1}) && ishandle(varargin{1})
HAxes=varargin{1}; % see if first argument is an MMPOLAR axes
if strcmp(get(HAxes,'Tag'),'MMPOLAR_Axes')
HFig=ancestor(HAxes,'figure');
HoldIsON=strcmp(get(HAxes,'nextplot'),'add')...
&& strcmp(get(HFig,'nextplot'),'add');
P=getappdata(HAxes,'MMPOLAR_Properties');
Pfn=fieldnames(P);
varargin(1)=[]; % strip initial axes handle off varargin
nargi=nargi-1; % varargin now contains rest of input arguments
else
local_error('First Argument is Not a Valid MMPOLAR Axes Handle.')
end
else % see if MMPOLAR axes is current axes
HFig=get(0,'CurrentFigure');
if isempty(HFig)
HAxes=[];
Pfn=fieldnames(local_getDefaults);
HoldIsON=false;
else
HAxes=get(HFig,'CurrentAxes');
if isempty(HAxes)
Pfn=fieldnames(local_getDefaults);
HoldIsON=false;
else
if strcmp(get(HAxes,'Tag'),'MMPOLAR_Axes')
HoldIsON=strcmp(get(HAxes,'nextplot'),'add')...
&& strcmp(get(HFig,'nextplot'),'add');
P=getappdata(HAxes,'MMPOLAR_Properties');
Pfn=fieldnames(P);
else % no MMPOLAR axes exists
HAxes=[];
Pfn=fieldnames(local_getDefaults);
HoldIsON=false;
set(HAxes,'NextPlot','replace') % hold off
end
end
end
end
%--------------------------------------------------------------------------
% Consider input arguments Consider input arguments
%--------------------------------------------------------------------------
if nargi==0 % MMPOLAR() MMPOLAR() MMPOLAR() MMPOLAR() MMPOLAR() MMPOLAR()
if ~isempty(HAxes)
out=P; % return property structure if it exists
return
else
local_error('No MMPOLAR Axes exists or is not Current Axes.')
end
end
if nargi==1 % Consider