⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mkplot.m

📁 控制系统计算机辅助设计——MATLAB语言与应用(源代码)
💻 M
字号:
function mkplot(x,y,w,plt)
%MKPLOT Mark points along a plot.
%       MKPLOT(X,Y,W,plt) marks the points (x,y) with
%       the numbers in the vector W.
%       If X and Y are matrices then columns are plotted
%       against columns.
%       The input argument plt is optional and specifies
%       1 or 4 plots per page.
%       If it is missing the default of 4 is used
%
%       MKPLT(C,W,plt) marks the curve specified by
%       real(C) versus imaginary(C)
%       Note C must have at least 1 non-zero imaginary part.
%
%       MKPLOT does not use all the points provided but tries
%       to ensure the annotations do not obscure each other.
%       Note: MKPLOT sets HOLD OFF at the end of the function.
%       MKPLOT should be the last operation applied to a plot.

%       Dr M.P. Ford 4th August 1987
% Copyright (c) 1987 by GEC Engineering Research Centre & Cambridge Control Ltd
% History:
%   Made Matlab 4.0 compatible; changes in 2 places, relating to `axis'
%       and `plot'. `Help' info changed slightly. 10.7.93, JMM.

%       The text spacing has been selected for Epson and HPGL plotters.
%       Change if necessary for your particular output device.

dx4=0.04;   % These are the ratios for one character to the plot width
dy4=0.09;   %   for 4 plots per page change if necessary
dx1=0.018;   % These are the ratios for one character to the plot width
dy1=0.035;   %   for 1 plot per page change if necessary

nargs=nargin;
error(nargchk(2,4,nargs));
if nargs==2
   w=y;
   y=imag(x);
   x=real(x);
   plt=4;
elseif nargs==3
      if (any(any(imag(x))))
	plt=w;
	w=y;
	y=imag(x);
	x=real(x);
      else
	plt=4;
      end
 % else nargs==4   use the inputs as is
end
if max(size(plt))~=1
   error('Plots/page not a scalar.');
end
if plt~=1
   strdx=dx4;
   strdy=dy4;
else
   strdx=dx1;
   strdy=dy1;
end

hold on;
[mx,nx]=size(x);
if min(mx,nx)==1   % x a vector
   x=x(:);
   y=y(:);
   nx=1;
   mx=length(x);
end
[my,ny]=size(y);
[mw,nw]=size(w);
if (ny~=nx)|(my~=mx)|(min(mw,nw)~=1)|(max(mw,nw)~=mx)
   error('Dimensions of inputs not consistent')
end
str=vec2str(w);
[mstr,nstr]=size(str);

for j=1:nx
%  axis('auto');    % auto range axis - Matlab 4.0 compatible,10.7.93,JMM.
% axis;            % auto range axis - original line
  strj=str;
  xj=x(:,j);
  yj=y(:,j);
  wax  = axis;  % Fix axis World axis coordinates
	   %  Now eliminate points outside the borders
  i=clip(xj,yj,wax);
  xj=xj(i);
  yj=yj(i);
  strj=strj(i,:);
     % now try to space out the text
     % text area = strdx*nstr*abs((wax(2)-wax(1))),
     %             strdy*abs((wax(4)-wax(3))
  dx=strdx*nstr*abs((wax(2)-wax(1)));
  dy=strdy*abs((wax(4)-wax(3)));
  if length(xj)~=0   % have some points left
     lastx=xj(1);
     lasty=yj(1);
     lxj=length(xj);
     in=zeros(1,lxj);
     in(1)=1;       % always have first point
     for i=2:lxj
	 if ((abs(xj(i)-lastx))<dx)&((abs(yj(i)-lasty))<dy)
	    % skip the point
	    in(i)=0;
	 else
	    in(i)=1;
	    lastx=xj(i);
	    lasty=yj(i);
	 end
     end   % for i=1:lxj
     xj=xj(in);
     yj=yj(in);
     strj=strj(in,:);
     text(xj,yj,strj);
     plot(xj,yj,'x');axis(wax);drawnow; % Matlab 4.0 compatible,10.7.93,JMM.
%    plot(xj,yj,'x');  % Original line
  else
     disp('No points inside the current plot''s borders.')
  end % if length(xj)~=0
end %  for j = 1:lxj
hold off

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -