📄 mmpolar.m
字号:
% Plot the Data Plot the Data
D.HLines=zeros(D.NumLines,1); % storage for lineseries handles
set([HFig,HAxes],'NextPlot','add') % hold on
for k=1:D.NumLines % plot the normalized data
tdata=D.TData{k};
rdata=D.RDataN{k};
xdata=rdata.*cos(tdata);
ydata=rdata.*sin(tdata);
D.HLines(k)=plot(HAxes,xdata,ydata,...
'Color',D.LineColor{k},...
'LineStyle',D.LineStyle{k},...
'Marker',D.Marker{k});
end
if HoldIsON
set([HFig,HAxes],'NextPlot','add') % hold on
else
set([HFig,HAxes],'NextPlot','replace') % hold off
end
% Store Data Store Data
setappdata(HAxes,'MMPOLAR_Properties',P)
setappdata(HAxes,'MMPOLAR_Data',D)
if nargout % output handles if requested
out=D.HLines;
end
% Update Plot with 'PName' PValue pairs if they exist
if exist('S','var')==1
local_updatePlot(HAxes,S)
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
% Local Functions Local Functions
%--------------------------------------------------------------------------
function local_updatePlot(HAxes,S) % local_updatePlot(HAxes,S)
% update MMPOLAR plot properties
% S contains known properties
P=getappdata(HAxes,'MMPOLAR_Properties');
D=getappdata(HAxes,'MMPOLAR_Data');
Sfn=fieldnames(S);
for kk=1:length(Sfn)
switch Sfn{kk}
case 'Axis' % Axis
[istrue,onoff]=local_isonoff(S.Axis);
if istrue
set(D.HAPatch,'Visible',onoff)
set(D.HRGrid,'Visible',onoff)
set(D.HTGrid,'Visible',onoff)
set(D.HRTick,'Visible',onoff)
set(D.HTTick,'Visible',onoff)
set(D.HRTickLabel,'Visible',onoff)
set(D.HTTickLabel,'Visible',onoff)
P.RGridVisible=onoff;
P.TGridVisible=onoff;
P.RTickLabelVisible=onoff;
P.TTickLabelVisible=onoff;
else
local_error('Unknown ''Axis'' Property Value.')
end
case 'BackgroundColor' % BackgroundColor
[istrue,cs]=local_iscolorspec(S.BackgroundColor);
if istrue
set(D.HAPatch,'FaceColor',cs)
P.BackgroundColor=cs;
else
local_error('Unknown ''BackgroundColor'' Property Value.')
end
case 'Border' % Border
[istrue,onoff]=local_isonoff(S.Border);
if istrue && strcmp(onoff,'on')
set(D.HAPatch,'EdgeColor',P.BorderColor)
set(D.HTTick,'Visible','on')
set(D.HRTick,'Visible','on')
P.RTickVisible='on';
P.TTickVisibel='on';
elseif istrue && strcmp(onoff,'off')
set(D.HAPatch,'EdgeColor','none')
set(D.HTTick,'Visible','off')
set(D.HRTick,'Visible','off')
P.RTickVisible='off';
P.TTickVisibel='off';
else
local_error('Unknown ''Border'' Property Value.')
end
case 'BorderColor' % BorderColor
[istrue,cs]=local_iscolorspec(S.BorderColor);
if istrue
P.BorderColor=cs;
set(D.HAPatch,'EdgeColor',cs)
set(D.HRTick,'Color',cs)
set(D.HTTick,'Color',cs)
else
local_error('Unknown ''BorderColor'' Property Value.')
end
case 'FontName' % FontName
if ischar(S.FontName) && any(strcmpi(listfonts,S.FontName))
set([D.HRTickLabel; D.HTTickLabel],'FontName',S.FontName)
P.FontName=S.FontName;
else
local_error('Unknown ''FontName'' Property Value.')
end
case 'FontSize' % FontSize
if isnumeric(S.FontSize) && isscalar(S.FontSize)
set([D.HRTickLabel; D.HTTickLabel],'FontSize',S.FontSize)
P.FontSize=S.FontSize;
else
local_error('Unknown ''FontSize'' Property Value.')
end
case 'FontWeight' % FontWeight
if ischar(S.FontWeight) && ...
(strncmpi(S.FontWeight,'normal',3)...
||strncmpi(S.FontWeight,'bold',3))
set([D.HRTickLabel; D.HTTickLabel],'FontWeight',S.FontWeight)
P.FontWeight=S.FontWeight;
else
local_error('Unknown ''FontWeight'' Property Value.')
end
case 'Grid' % Grid
[istrue,onoff]=local_isonoff(S.Grid);
if istrue
set(D.HRGrid,'Visible',onoff)
set(D.HTGrid,'Visible',onoff)
P.Grid=onoff;
P.RGridVisible=onoff;
P.TGridVisible=onoff;
else
local_error('Unknown ''Grid'' Property Value.')
end
case 'RGridColor' % RGridColor
[istrue,cs]=local_iscolorspec(S.RGridColor);
if istrue
set(D.HRGrid,'Color',cs)
set(D.HRTickLabel,'Color',cs)
P.RGridColor=cs;
else
local_error('Unknown ''RGridColor'' Property Value.')
end
case 'RGridLineStyle' % RGridLineStyle
if local_islinespec(S.RGridLineStyle)
set(D.HRGrid,'LineStyle',S.RGridLineStyle)
P.RGridLineStyle=S.RGridLineStyle;
else
local_error('Unknown ''RGridLineStyle'' Property Value.')
end
case 'RGridLineWidth' % RGridLineWidth
if isnumeric(S.RGridLineWidth) && isscalar(S.RGridLineWidth)
set(D.HRGrid,'LineWidth',S.RGridLineWidth)
P.RGridLineWidth=S.RGridLineWidth;
else
local_error('Unknown ''RGridLineWidth'' Property Value.')
end
case 'RGridVisible' % RGridVisible
[istrue,onoff]=local_isonoff(S.RGridVisible);
if istrue
set(D.HRGrid,'Visible',onoff)
P.RGridVisible=onoff;
else
local_error('Unknown ''RGridVisible'' Property Value.')
end
case 'RLimit' % RLimit
if isnumeric(S.RLimit) && numel(S.RLimit)==2
S.RLimit=[min(S.RLimit) max(S.RLimit)];
S.RLimit(isinf(S.RLimit))=P.RLimit(isinf(S.RLimit));
[P,D]=local_getRTickValue(HAxes,P,D,S);
[P,D]=local_placeRGrid(HAxes,P,D,S);
[P,D]=local_placeRTickLabel(HAxes,P,D,S);
% rescale rho data to new limits
for k=1:length(D.RData)
D.RDataN(k)={(D.RData{k}-D.RMin)/D.RLimitDiff};
D.RDataN{k}(D.RDataN{k}>1)=NaN; % hide data outside limits
D.RDataN{k}(D.RDataN{k}<0)=NaN;
theta=D.TData{k};
xdata=D.RDataN{k}.*cos(theta);
ydata=D.RDataN{k}.*sin(theta);
set(D.HLines(k),'XData',xdata,'YData',ydata)
end
else
local_error('Unknown ''RLimit'' Property Value.')
end
case 'RTickAngle' % RTickAngle
if isnumeric(S.RTickAngle) && isscalar(S.RTickAngle)
rad=S.RTickAngle;
if strcmp(P.TTickScale,'degrees')
rad=S.RTickAngle*pi/180;
end
if P.TLimit(1)>P.TLimit(2) && (rad<P.TLimit(2) || rad>P.TLimit(1))
P.RTickAngle=S.RTickAngle;
D.RTickAngle=rad;
elseif rad>P.TLimit(1) && rad<P.TLimit(2)
P.RTickAngle=S.RTickAngle;
D.RTickAngle=rad;
else
local_error('RTickAngle not within Theta Axis Limits.')
end
for k=1:D.RTickLabelN % ignore innermost tick
xdata=(P.RTickOffset+D.RTickRadius(k))*cos(D.RTickAngle);
ydata=(P.RTickOffset+D.RTickRadius(k))*sin(D.RTickAngle);
set(D.HRTickLabel(k),'Position',[xdata ydata])
end
phi=asin(P.TickLength./(2*D.RTickRadius));
tdata=[D.RTickAngle-phi; D.RTickAngle+zeros(size(D.RTickRadius))
D.RTickAngle+phi; NaN(size(D.RTickRadius))];
rdata=[D.RTickRadius; D.RTickRadius
D.RTickRadius; NaN(size(D.RTickRadius))];
xdata=rdata(:).*cos(tdata(:));
ydata=rdata(:).*sin(tdata(:));
set(D.HRTick,'XData',xdata,'YData',ydata) % move rho ticks
else
local_error('Unknown ''RTickAngle'' Property Value.')
end
case 'RTickLabel' % RTickLabel
if iscellstr(S.RTickLabel)
NumS=length(S.RTickLabel);
for k=1:D.RTickLabelN
str=S.RTickLabel{rem(k-1,NumS)+1};
set(D.HRTickLabel(k),'String',str)
end
P.RTickLabel=S.RTickLabel;
else
local_error('Unknown ''RTickLabel'' Property Value.')
end
case 'RTickLabelHalign' % RTickLabelHalign
fnames={'left' 'center' 'right'};
out=local_isfield(fnames,S.RTickLabelHalign);
if ~isempty(out)
P.RTickLabelHalign=out;
set(D.HRTickLabel,'HorizontalAlignment',out)
else
local_error('Unknown ''RTickLabelHalign'' Property Value.')
end
case 'RTickLabelValign' % RTickLabelValign
fnames={'top' 'cap' 'middle' 'baseline' 'bottom'};
out=local_isfield(fnames,S.RTickLabelValign);
if ~isempty(out)
P.RTickLabelValign=out;
set(D.HRTickLabel,'VerticalAlignment',out)
else
local_error('Unknown ''RTickLabelValign'' Property Value.')
end
case 'RTickLabelVisible' % RTickLabelVisible
[istrue,onoff]=local_isonoff(S.RTickLabelVisible);
if istrue
set(D.HRTickLabel,'Visible',onoff)
P.RTickLabelVisible=onoff;
else
local_error('Unknown ''RTickLabelVisible'' Property Value.')
end
case 'RTickOffset' % RTickOffset
if isnumeric(S.RTickOffset) && isscalar(S.RTickOffset)
P.RTickOffset=S.RTickOffset;
for k=1:D.RTickLabelN
xdata=(P.RTickOffset+D.RTickRadius(k))*cos(D.RTickAngle);
ydata=(P.RTickOffset+D.RTickRadius(k))*sin(D.RTickAngle);
set(D.HRTickLabel(k),'Position',[xdata ydata])
end
else
local_error('Unknown ''RTickOffset'' Property Value.')
end
case 'RTickUnits' % RTickUnits
if ischar(S.RTickUnits)
tmp=char(get(D.HRTickLabel(end),'String'));
if ~isempty(P.RTickUnits)
idx=strfind(tmp,P.RTickUnits);
tmp=[tmp(1:idx(end)-1) S.RTickUnits];
else
tmp=[tmp S.RTickUnits]; %#ok
end
set(D.HRTickLabel(end),'String',tmp)
P.RTickUnits=S.RTickUnits;
else
local_error('Unknown ''RTickUnits'' Property Value.')
end
case 'RTickValue' % RTickValue
if isnumeric(S.RTickValue) && numel(S.RTickValue)>0
S.RTickValue=S.RTickValue(S.RTickValue>=P.RLimit(1)...
& S.RTickValue<=P.RLimit(2));
if length(S.RTickValue)>1
P.RTickValue=S.RTickValue;
D.RTickLabelN=length(P.RTickValue);
D.RTickRadius=(P.RTickValue-D.RMin)/D.RLimitDiff;
[P,D]=local_placeRGrid(HAxes,P,D,S);
[P,D]=local_placeRTickLabel(HAxes,P,D,S);
end
else
local_error('Unknown ''RTickValue'' Property Value.')
end
case 'RTickVisible' % RTickVisible
[istrue,onoff]=local_isonoff(S.RTickVisible);
if istrue
set(D.HRTick,'Visible',onoff)
P.RTickVisible=onoff;
else
local_error('Unknown ''RTickVisible'' Property Value.')
end
case 'Style' % Style
if strncmpi(S.Style,'cartesian',3) % Cartesian style
set(HAxes,'View',[0 90])
P.TDirection='ccw';
P.TZeroDirection='east';
P.Style='cartesian';
elseif strncmpi(S.Style,'compass',3) % Compass style
set(HAxes,'View',[90 -90])
P.TDirection='cw';
P.TZeroDirection='north';
P.Style='compass';
else
local_error('Unknown ''Style'' Property Value.')
end
case 'TDirection' % TDirection
if ischar(S.TDirection) && strcmpi(S.TDirection,'cw')
P.TDirection='cw';
if strcmp(P.TZeroDirection,'north')
set(HAxes,'View',[90 -90])
elseif strcmp(P.TZeroDirection,'east')
set(HAxes,'View',[0 -90])
elseif strcmp(P.TZeroDirection,'south')
set(HAxes,'View',[270 -90])
elseif strcmp(P.TZeroDirection,'west')
set(HAxes,'View',[180 -90])
end
elseif ischar(S.TDirection) && strcmpi(S.TDirection,'ccw')
P.TDirection='ccw';
if strcmp(P.TZeroDirection,'north')
set(HAxes,'View',[270 90])
elseif strcmp(P.TZeroDirection,'east')
set(HAxes,'View',[0 90])
elseif strcmp(P.TZeroDirection,'south')
set(HAxes,'View',[90 90])
elseif strcmp(P.TZeroDirection,'west')
set(HAxes,'View',[180 90])
end
else
local_error('Unknown ''TDirection'' Property Value.')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -