📄 pplot.m
字号:
idxtagstr = find(strcmpi(Prop,'tag')); % Store line tag
if ~isempty(idxtagstr)
s = get(gca,'UserData');
if isstruct(s) && isfield(s,'LastLineTag')
s.LastLineTag = Prop{idxtagstr + 1};
set(gca,'UserData',s)
end
end
else % Labels
defLabProp = {'Clipping','on','FontSize',7};
if PtLab || BFPtLab % Point labels
if PtLab
if size(XY,1) > 2
IJ = tri2list(delaunay(XY(:,1),XY(:,2)));
elseif size(XY,1) > 1
IJ = [1 2];
else
IJ = [1 1];
end
elseif ~isempty(rte)
IJ = [];
for k = 1:length(rte)
i = rte{k}(1:end-1); j = rte{k}(2:end);
IJ = [IJ; i(:) j(:)];
end
end
A = list2adj(IJ);
A = A + A';
hout = [];
for i = 1:m
[halign,valign,labstr,ang,padspace] = bestfitpos(PtLab,...
XY(i,:),XY(find(A(:,i)),:),makelabstr(Labels{i}));
LabProp = {defLabProp{:},'HorizontalAlignment',halign,...
'VerticalAlignment',valign,Prop{:}};
houti = text(XY(i,1),XY(i,2),labstr,LabProp{:});
extent = get(houti,'Extent'); % Reposition if text box
XLim = get(gca,'XLim'); % is outside of X-axis
if extent(1) + extent(3) > XLim(2) % limits
set(houti,'HorizontalAlignment','right',...
'String',[get(houti,'String') blanks(padspace)]);
elseif extent(1) < XLim(1)
set(houti,'HorizontalAlignment','left',...
'String',[blanks(padspace) get(houti,'String')]);
end
hout = [hout; houti];
end
elseif ArcLab % Arc labels
hout = [];
for i = 1:n
[loc,ang,orient] = arcpos(XY(IJ(i,1),:),XY(IJ(i,2),:));
LabProp = {defLabProp{:},'HorizontalAlignment','center',...
'VerticalAlignment',orient,'Rotation',ang,Prop{:}};
hout = [hout; text(loc(1),loc(2),makelabstr(Labels{i}),LabProp{:})];
end
elseif SingleRteLab % Single route labels
hout = [];
if length(rte{1}) > 1
for i = 1:length(rte{1})-1
[loc,ang,orient] = arcpos(XY(rte{1}(i),:),XY(rte{1}(i+1),:));
LabProp = {defLabProp{:},'HorizontalAlignment','center',...
'VerticalAlignment',orient,'Rotation',ang,Prop{:}};
hout = [hout; ...
text(loc(1),loc(2),makelabstr(Labels{i}),LabProp{:})];
end
end
elseif MultiRteLab % Multiple route labels
hout = [];
for i = 1:length(rte)
if length(rte{i}) > 1
% Use arc from first and last points on route for label angle
[loc,ang,orient] = arcpos(XY(rte{i}(1),:),XY(rte{i}(end),:));
loc = mean(XY(rte{i},:)); % Use centroid for label location
LabProp = {defLabProp{:},'HorizontalAlignment','center',...
'VerticalAlignment',orient,'Rotation',ang,Prop{:}};
hout = [hout; ...
text(loc(1),loc(2),makelabstr(Labels{i}),LabProp{:})];
end
end
end
end
if isempty(Labels) % Border offset
if isempty(border)
if strcmp(get(gca,'Tag'),'proj'), border = 0; else border = 0.2; end
end
if border > 0
xy1xy2 = boundrect(XY,border);
XYLim = [get(gca,'XLim')' get(gca,'YLim')'];
xy1xy2 = [min(xy1xy2(1,:),XYLim(1,:)); max(xy1xy2(2,:),XYLim(2,:))];
s = get(gca,'UserData'); % Check for Maximum X,Y Limits
if isstruct(s) && isfield(s,'MaxXYLim') && ~isempty(s.MaxXYLim)
xy1xy2 = [max(xy1xy2(1,:),s.MaxXYLim(1,:)); ...
min(xy1xy2(2,:),s.MaxXYLim(2,:))];
end
set(gca,'XLim',xy1xy2(:,1))
set(gca,'YLim',xy1xy2(:,2))
end
end
if strcmp(get(gca,'Tag'),'proj'), projtick, end
if nargout > 0, h = hout; end
shg % Re-draw plot on screen
% *************************************************************************
% *************************************************************************
% *************************************************************************
function [halign,valign,labstr,ang,padspace] = ...
bestfitpos(PtLab,xy,XY,labstr)
%BESTFITPOS Best-fit label at point xy relative to arcs from xy to XY.
padspace = 1; % No. of spaces to pad in order to offset text from point
threshratio = 2; % Threshold ratio to cut off edges of Delaunay tri.
if isempty(XY) || all(all(is0(xy(ones(size(XY,1),1),:) - XY)))
ang = 0;
valign = 'top';
halign = 'left';
else
if PtLab % Use edges from Delaunay triangulation
d = dists(xy,XY,2);
XY = XY(d/min(d) <= threshratio,:);
end
ang = sort(arcang(xy,XY));
if size(XY,1) == 1 % Label opposite single arc
ang = ang + 180;
else % Label between max arc angle gap
d = diff([-180; ang; 180]);
d = [d(2:end-1); d(1) + d(end)];
idx = argmax(d);
ang = ang(idx) + d(idx)/2; % Note: ang can only be > 180, not < -180
end
if ang < 0, ang = 360 + ang; end % Convert to range 0 to 360 degrees
rng = [ 0 1 3 5 7 9 11 13 15 16]*22.5;
%idx =[ 1 2 3 4 5 6 7 8 9 10];
% E1 NE N NW W SW S SE E2
idx = find(ang >= rng(1:9) & ang < rng(2:10));
if ismember(idx,[4 5 6])
halign = 'right';
labstr = [labstr blanks(padspace)];
elseif ismember(idx,[3 7])
halign = 'center';
else
halign = 'left';
labstr = [blanks(padspace) labstr];
end
if ismember(idx,[2 3 4])
valign = 'bottom';
elseif ismember(idx,[1 5 9])
valign = 'middle';
else
valign = 'top';
end
end
% *************************************************************************
% *************************************************************************
% *************************************************************************
function [loc,ang,orient] = arcpos(xy1,xy2)
%ARCPOS Location, angle, and orientation for arc labels.
loc = (xy1 + xy2)/2;
ang = arcang(xy1,xy2);
if all(is0(xy1-xy2))
orient = 'middle';
elseif ang < 90 && ang >= -90
orient = 'bottom';
else
orient = 'top';
end
if ang >= 90, ang = ang - 180; elseif ang < -90, ang = ang + 180; end
% *************************************************************************
% *************************************************************************
% *************************************************************************
function ang = arcang(xy,XY)
%ARCANG Arc angles (in degrees) from xy to XY.
if ~isempty(XY)
ang = 180*atan2(XY(:,2) - xy(2), XY(:,1) - xy(1))/pi;
else
ang = 0;
end
% *************************************************************************
% *************************************************************************
% *************************************************************************
function labstr = makelabstr(labstr)
%NUMLAB2LABSTR Convert numeric label to a label string..
if isnumeric(labstr)
labstr = num2str(labstr);
elseif ~ischar(labstr)
error('Label elements must be a string or a number.')
end
% *************************************************************************
% *************************************************************************
% *************************************************************************
function h = matlogmenu(hfig)
%MATLOGMENU Create Matlog menu on the current figure's menu bar
% h = handle of menu object created
% Input Error Checking ****************************************************
if nargin < 1 || isempty(hfig)
hfig = gcf;
elseif ishandle(hfig) && ~strcmp(get(hfig,'Type'),'figure')
error('"hfig" must be a figure handle.')
end
% End (Input Error Checking) **********************************************
% Top-Level Menu
hout = uimenu('Label','&Matlog');
if nargout > 0, h = hout; end
% Menu Elements
uimenu(hout,'Label','&Re-Project Ticks','Callback','projtick',...
'Accelerator','R')
uimenu(hout,'Label','&Set Pauseplot Time','Callback','pauseplot(''set'')')
uimenu(hout,'Label','&Erase Last Line Tag','Callback',...
'deletelntag','Accelerator','D')
% Help and About Matlog Menu Elements
uimenu(hout,'Label','Matlog &Help','Separator','on','Callback',...
'helpwin(''matlog'')')
uimenu(hout,'Label','&About Matlog...','Callback',...
['msgbox({''Logistics Engineering Toolbox'''...
','' '',''http://www.ie.ncsu.edu/kay/matlog''},''Matlog'')'])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -