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

📄 legd_proc.m

📁 很优良的PID控制器设计仿真程序与模型,经过严格检验
💻 M
📖 第 1 页 / 共 2 页
字号:
   uu=get(g_graphs,'UserData'); if nTask~=10, uu{2}(2)=nTask; end, 
   set(g_graphs,'UserData',uu);
end

%-------------------------------------------------------------------------------
%get_exact_point function is used to get the exact position in the axis when the 
%mouse is moved.  
%
%     [x,y]=get_exact_point
%where 
%  [x,y] returns the exact coordinate of the point
%-------------------------------------------------------------------------------
function [x,y]=get_exact_point()
nXAxis=get(gca,'XLim'); nYAxis=get(gca,'YLim'); ptAxis=get(gca,'Position');
x0=ptAxis(1); y0=ptAxis(2); xyPt=get(gcf,'CurrentPoint');
xyPt(1:2)=xyPt(1:2)-ptAxis(1:2);
x=xyPt(1)*diff(nXAxis)/ptAxis(3)+nXAxis(1); y=xyPt(2)*diff(nYAxis)/ptAxis(4)+nYAxis(1);

%---------------------------------------------------------------------
%get_legnd function is used to get the handle of the specified object.
%
%     [iLegend,y,button]=get_legnd(nTask)
%where 
%  nTask -- the task code, details see the case comments
%---------------------------------------------------------------------
function [iLegend,y,button]=get_legnd(nTask)
ii=extra_funs(2,'axes'); h_lines=[]; h_text=[];
for i=1:length(ii)
   axes(ii(i))
   if nTask==2, h_lines=[]; %In editting mode, exclude the lines/curves
   else, h_lines=[h_lines; extra_funs(2,'line',1)]; %otherwise find the handle of lines
   end
   %find the handle of all the text
   h_text=[h_text; extra_funs(2,'text',1)];
end
y=[]; buttton=[]; key=0; iLegend=[]; ii=[]; 
while key==0
   [x,y,button]=ginput(1);
   if button~=1, iLegend=[]; break; end
   switch nTask
   case {1,5}, %if it is a curve
      for i=1:length(h_lines)
         if length(get(h_lines(i),'XData'))>5, ii=[ii;i]; end
      end
      if length(h_lines(ii))>0
         if any(h_lines(ii)==gco), key=1; 
            if nTask==1, iLegend=x; else, iLegend=gco; end
         end
      else, 
         warndlg('Sorry, there is no curve to be processed!','Warning: Process failed!'), 
         iLegend=[]; break; 
      end   
   case {2,3,4,6},  %if it is a legend
      if nTask==6, hh=[h_lines; h_text];
      else, %make all the handles of legends
         for i=1:length(h_lines)
            if length(get(h_lines(i),'XData'))<=5, 
               ii=[ii,i]; if nTask==3, set(gco,'UserData',[x,y]); end
            end
         end
         hh=[h_lines(ii); h_text];
      end
      if length(hh)>0
         if any(hh==gco), iLegend=gco;  key=1;
            if nTask==4, 
               uu0=get(gco,'UserData'); if length(uu0)==1, iLegend=[iLegend; uu0]; end
            end
         end
      else, 
         warndlg('Sorry, there is no legends to be processed!','Warning: Process failed!'), 
         iLegend=[]; break; 
      end   
   end   
end

%-----------------------------------------------------------------------
%set_text_prop function is used to set the properties of the text object 
%according to users specifications
%
%  set_text_prop(hh)
%where 
%  hh -- the handle to be modified
%-----------------------------------------------------------------------
function set_text_prop(hh)
gg=get(findobj('Tag','CtrlLABLegends'),'UserData');

hFont=get(gg{1}(3),'UserData');
if length(hFont)>0
   [v,d]=version; v1=eval(v(1)); v2=eval(v(3));
   if v2<=1
      if hFont~=0
         set(hh,'FontName',get(hFont,'FontName'),'FontSize',get(hFont,'FontSize'),...
                'FontAngle',get(hFont,'FontAngle'),'FontWeight',get(hFont,'FontWeight'));
      end
   else
      if isa(hFont,'struct')
         set(hh,'FontName',hFont.FontName,'FontSize',hFont.FontSize,...
                'FontAngle',hFont.FontAngle,'FontWeight',hFont.FontWeight);
      end
   end   
end   
if strcmp(get(gg{1}(13),'Visible'),'on')
   set(hh,'Rotation',eval(get(gg{1}(13),'String')));
end

%----------------------------------------------------------------------------
%set_color_prop function is used to set the color properties of the text/line 
%object according to users specifications
%
%  set_color_prop(hh)
%where 
%  hh -- the handle to be modified
%----------------------------------------------------------------------------
function set_color_prop(hh)
uu=get(findobj('Tag','CtrlLABLegends'),'UserData'); 
nColor=get(uu{1}(2),'UserData');
if length(nColor)==3, set(hh,'Color',nColor); end

%---------------------------------------------------------------------------------
%set_line_prop function is used to set the properties of the line object according
%to users specifications
%
%  set_line_prop(hh)
%where 
%  hh -- the handle to be modified
%---------------------------------------------------------------------------------
function set_line_prop(hh)
gg=get(findobj('Tag','CtrlLABLegends'),'UserData'); 
if length(get(gg{1}(6),'UserData'))>0
   keyStyle1=get(gg{1}(6),'Value');
   switch keyStyle1
   case 1, keySign1='-'; 
   case 2, keySign1='--';
   case 3, keySign1=':';
   case 4, keySign1='-.'; 
   end
   set(hh,'LineStyle',keySign1)   
end
if length(get(gg{1}(8),'UserData'))>0
   LineCurrent=get(hh,'LineWidth');
   if get(gg{1}(8),'Value')==0, LineCurrent=LineCurrent*2;
   else, LineCurrent=LineCurrent*0.5; end   
   set(hh,'LineWidth',LineCurrent);
end
if length(get(gg{1}(15),'UserData'))>0
   keyStyle1=get(gg{1}(15),'Value');
   strMarker=str2mat('+ sign','o sign','* sign','. sign','x sign','square','diamond',...
      'v sign','^ sign','> sign','< sign','pentagram','hexagram','remove marker');
   switch keyStyle1
   case 1, keySign1='+'; 
   case 2, keySign1='o';
   case 3, keySign1='*';
   case 4, keySign1='.'; 
   case 5, keySign1='x'; 
   case 6, keySign1='square'; 
   case 7, keySign1='diamond'; 
   case 8, keySign1='v';
   case 9, keySign1='^';
   case 10, keySign1='>'; 
   case 11, keySign1='<'; 
   case 12, keySign1='pentagram'; 
   case 13, keySign1='hexagram'; 
   case 14, keySign1='none'; 
   end
   set(hh,'Marker',keySign1)   
end

%----------------------------------------------------------------------------------
%plt_range_box function is used to display the dialog box for plot range parameters
%----------------------------------------------------------------------------------
function plt_range_box()
g_plot=gcf; uu=get(g_plot,'UserData'); nPlot=uu{3};
if length(extra_funs(2))>0
   xx=get(gca,'XLim'); h_lines=extra_funs(2,'line',1); n_points=0;
   for i=1:length(h_lines)
      xd=get(h_lines(i),'XData'); 
      if length(xd)>5, 
         if n_points<length(xd); n_points=length(xd); end
         g_dat=get(h_lines(i),'UserData');
         if length(g_dat)>0, xx=[g_dat(1),g_dat(length(g_dat))]; break; end
      end   
   end   
   x1=xx(1); x2=xx(2); 
else, xx=[]; end   

h_win=findobj('Tag','CtrlLABPlots');
if length(h_win)==0
   h_win=figure('Units','normalized','Position',[0.24875 0.3 0.375 0.25],...
      'NumberTitle','off','Name','Change Plot Range','Tag','CtrlLABPlots',...
      'MenuBar','none','Color',0.8*[1,1,1],'Resize','off');         
   extra_funs(1);
   hFF(1)=uicontrol('Style','Pushbutton','String','Change',...
      'Units','normalized','Position',[0.8,0.8,0.18,0.16],'Callback','legd_proc(25);');
   hFF(2)=uicontrol('Style','Pushbutton','String','Cancel',...
      'Units','normalized','Position',[0.8,0.6,0.18,0.16],'Callback','close(gcf);');
   hFF(3)=uicontrol('Style','Pushbutton','String','Help',...
      'Units','normalized','Position',[0.8,0.4,0.18,0.16],'Callback','clab_help(31);');
   [xL,hRng(1)]=display_str(0.05,0.8,'Simulation Start Time',[0,0,0],'on',9);
   hRng(2)=uicontrol('Style','Edit','BackgroundColor',[1,1,1],...
      'Units','normalized','Position',[0.45,0.73,0.15,0.14]);
   [xL,hRng(3)]=display_str(0.05,0.6,'Simulation Stop Time',[0,0,0],'on',9);
   hRng(4)=uicontrol('Style','Edit','BackgroundColor',[1,1,1],...
      'Units','normalized','Position',[0.45,0.53,0.15,0.14]);
   [xL,hRng(5)]=display_str(0.05,0.40,'Number of Points',[0,0,0],'on',9);
   hRng(6)=uicontrol('Style','Edit','BackgroundColor',[1,1,1],...
      'Units','normalized','Position',[0.45,0.33,0.15,0.14]);
   [v,d]=version; v1=eval(v(1)); v2=eval(v(3)); v3=eval(v(5));
   if v2==2 & v3==0, strCheck='ToggleButton'; else, strCheck='CheckBox'; end 
   hRng(7)=uicontrol('Style',strCheck,'String','Use SIMULINK',...
      'Units','normalized','Position',[0.08,0.15,0.45,0.14],...
      'Enable','off','BackgroundColor',0.8*[1,1,1]);
   hRng(8)=uicontrol('Style',strCheck,'String','Use Pade Approximation',...
      'Units','normalized','Position',[0.48,0.15,0.45,0.14],...
      'Enable','off','BackgroundColor',0.8*[1,1,1]);
   set(h_win,'UserData',{hFF,hRng,g_plot,nPlot})
else, 
   figure(h_win); 
   uu0=get(gcf,'UserData'); hFF=uu0{1}; hRng=uu0{2}; g_plot=uu0{3};
end
switch nPlot
case {1,2,3,4}
   set(hRng(1),'String','Starting Frequency'); set(hRng(3),'String','Stopping Frequency');
   set(hRng(7),'String','Use Pade Approximation');
   if length(xx)==0, x1=0.1; x2=100; n_points=100; end
case 5,    
   set(hRng(1),'String','Smallest Gain'); set(hRng(3),'String','Highest Gain');
   set(hRng(7),'Visible','off');
   if length(xx)==0, x1=0; x2=10; n_points=100; end
case {6,7}
   if length(xx)==0, x1=0; x2=10; n_points=100; end
end
set(hRng(2),'String',num2str(x1)); set(hRng(4),'String',num2str(x2));
set(hRng(6),'String',int2str(n_points));
key_dly=proc_model(7); key_sim=proc_model(8);

set(hRng(8),'Enable',extra_funs(6,key_dly));
if nPlot>5, set(hRng(7),'Enable',extra_funs(6,key_sim)); end   

⌨️ 快捷键说明

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