📄 fuzzy.asv
字号:
%delete(f_1);
set(f_1,'visible','off');
set(gcf,'defaultuicontrolunits','normalized');
H=axes('unit','normalized','position',[0,0,1,1],'visible','off');
%全局设置
top=0.98;
bottom=0.15;
left=0.05;
right=0.95;
textHeight = 0.05;
textWidth = 0.22;
labelWidth= 0.13;
radioWidth=0.35;
spacing=0.01;
%创建用户控件区
frmPos=[left bottom right-left top-bottom];
f_2=uicontrol(...
'style','frame',...
'position',frmPos,...
'background',[0.5 0.5 0.5]);
%ga 参数
labelBottom=top-textHeight-spacing;
labelLeft = left+0.05;
labelPos = [labelLeft labelBottom labelWidth textHeight];
t_1 = uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'Horiz','left', ...
'String','变异概率', ...
'Interruptible','off', ...
'BackgroundColor',[0.5 0.5 0.5], ...
'ForegroundColor','white',...
'TooltipString','Sampling Frequency');
%text(0.1,0.95,'变异概率:','fontsize',10);
textPos = [labelLeft+labelWidth labelBottom textWidth textHeight];
e_pmutation= uicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Position',textPos, ...
'Horiz','center', ...
'Background','white', ...
'Foreground','black', ...
'String','0.015','Userdata',0.015);
labelBottom=top-2*textHeight-2*spacing;
labelPos = [labelLeft labelBottom labelWidth textHeight];
t_2 = uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'Horiz','left', ...
'String','交叉概率', ...
'Interruptible','off', ...
'BackgroundColor',[0.5 0.5 0.5], ...
'ForegroundColor','white');
%text(0.1,0.85,'交叉概率:','fontsize',10);
textPos = [labelLeft+labelWidth labelBottom textWidth textHeight];
e_pcross=uicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Position',textPos, ...
'Horiz','center', ...
'Background','white', ...
'Foreground','black', ...
'String','0.1','Userdata',0.1);
%uicontrol(gcf,'style','edit','background','white',...
% 'position',[0.25,0.825,0.15,0.05],'string','0.1');
labelBottom=top-3*textHeight-3*spacing;
labelPos = [labelLeft labelBottom labelWidth textHeight];
t_3 = uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'Horiz','left', ...
'String','最大世代数', ...
'Interruptible','off', ...
'BackgroundColor',[0.5 0.5 0.5], ...
'ForegroundColor','white');
%text(0.1,0.75,'最大世代数:','fontsize',10);
textPos = [labelLeft+labelWidth labelBottom textWidth textHeight];
e_maxgen=uicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Position',textPos, ...
'Horiz','center', ...
'Background','white', ...
'Foreground','black', ...
'String','50','Userdata',50);
%uicontrol(gcf,'style','edit','background','white',...
% 'position',[0.25,0.725,0.15,0.05],'string','50');
labelBottom=top-4*textHeight-4*spacing;
labelPos = [labelLeft labelBottom labelWidth textHeight];
t_4 = uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'Horiz','left', ...
'String','染色体长度', ...
'Interruptible','off', ...
'BackgroundColor',[0.5 0.5 0.5], ...
'ForegroundColor','white');
%text(0.1,0.65,'染色体长度:','fontsize',10);
textPos = [labelLeft+labelWidth labelBottom textWidth textHeight];
e_lchrom=uicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Position',textPos, ...
'Horiz','center', ...
'Background','white', ...
'Foreground','black', ...
'String','8','Userdata',8);
%uicontrol(gcf,'style','edit','background','white',...
% 'position',[0.25,0.625,0.15,0.05],'string','8');
labelBottom=top-5*textHeight-5*spacing;
labelPos = [labelLeft labelBottom labelWidth textHeight];
t_5 = uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'Horiz','left', ...
'String','种群大小', ...
'Interruptible','off', ...
'BackgroundColor',[0.5 0.5 0.5], ...
'ForegroundColor','white');
%text(0.1,0.55,'种群大小:','fontsize',10);
textPos = [labelLeft+labelWidth labelBottom textWidth textHeight];
e_popsize=uicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Position',textPos, ...
'Horiz','center', ...
'Background','white', ...
'Foreground','black', ...
'String','20','Userdata',20);
%e_popsize=uicontrol(gcf,'style','edit','background','white',...
% 'position',[0.25,0.525,0.15,0.05],'string','20');
%控制器参数
labelBottom=top-6*textHeight-6*spacing;
labelPos = [labelLeft labelBottom labelWidth textHeight];
r_rule=uicontrol(gcf,'style','radio','string','一阶系统 ','position',labelPos);
set(r_rule,'value',get(r_pidorder1,'Max'));
set(r_rule,'callback',['order=1;',...
'set(r_pidorder1,''value'',get(r_pidorder1,''Max'')),',...
'set(r_pidorder2,''value'',get(r_pidorder2,''Min'')),',...
'set(r_pidorder3,''value'',get(r_pidorder3,''Min'')),',...
]);
labelBottom=top-7*textHeight-7*spacing;
labelPos = [labelLeft labelBottom labelWidth textHeight];
r_memb=uicontrol(gcf,'style','radio','string','二阶系统 ','position',labelPos);
set(r_pidorder2,'callback',[...
'order=2;set(r_pidorder2,''value'',get(r_pidorder2,''Max'')),',...
'set(r_pidorder1,''value'',get(r_pidorder1,''Min'')),',...
'set(r_pidorder3,''value'',get(r_pidorder3,''Min'')),',...
]);
labelBottom=top-8*textHeight-8*spacing;
labelPos = [labelLeft labelBottom labelWidth textHeight];
r_r_r&m=uicontrol(gcf,'style','radio','string','三阶系统 ','position',labelPos);
set(r_r&m,'callback',[...
'order=3;set(r_pidorder3,''value'',get(r_pidorder3,''Max'')),',...
'set(r_pidorder1,''value'',get(r_pidorder1,''Min'')),',...
'set(r_pidorder2,''value'',get(r_pidorder2,''Min'')),',...
]);
%对象参数
%text(0.6,0.86,'对象级别:','fontsize',10);
labelBottom=top-9*textHeight-9*spacing;
labelPos = [labelLeft labelBottom radioWidth textHeight];
r_pidorder1=uicontrol(gcf,'style','radio','string','一阶系统 ',...
'position',labelPos);
set(r_pidorder1,'value',get(r_pidorder1,'Max'));
order=1;differ='yout(k)=-den(2)*y_1+num(2)*u_1;';
set(r_pidorder1,'callback',['order=1;',...
'differ=''yout(k)=-den(2)*y_1+num(2)*u_1;'';',...
'set(r_pidorder1,''value'',get(r_pidorder1,''Max'')),',...
'set(r_pidorder2,''value'',get(r_pidorder2,''Min'')),',...
'set(r_pidorder3,''value'',get(r_pidorder3,''Min'')),',...
'set(e_gs,''string'',''[0 1],[1 -1]''),',...
]);
labelBottom=top-10*textHeight-10*spacing;
labelPos = [labelLeft labelBottom radioWidth textHeight];
r_pidorder2=uicontrol(gcf,'style','radio','string','二阶系统 ',...
'position',labelPos);
set(r_pidorder2,'callback',[...
'differ=''yout(k)=-den(2)*y_1-den(3)*y_2+num(2)*u_1+num(3)*u_2;'';',...
'order=2;set(r_pidorder2,''value'',get(r_pidorder2,''Max'')),',...
'set(r_pidorder1,''value'',get(r_pidorder1,''Min'')),',...
'set(r_pidorder3,''value'',get(r_pidorder3,''Min'')),',...
'set(e_gs,''string'',''[0 0 400],[1 50 0]''),',...
]);
labelBottom=top-11*textHeight-11*spacing;
labelPos = [labelLeft labelBottom radioWidth textHeight];
r_pidorder3=uicontrol(gcf,'style','radio','string','三阶系统 ',...
'position',labelPos);
set(r_pidorder3,'callback',[...
'differ=''yout(k)=-den(2)*y_1-den(3)*y_2-den(4)*y_3+num(2)*u_1+num(3)*u_2+num(4)*u_3;'';',...
'order=3;set(r_pidorder3,''value'',get(r_pidorder3,''Max'')),',...
'set(r_pidorder1,''value'',get(r_pidorder1,''Min'')),',...
'set(r_pidorder2,''value'',get(r_pidorder2,''Min'')),',...
'set(e_gs,''string'',''[0 0 0 1],[1 -3 2 0]''),',...
]);
labelBottom=top-12*textHeight-12*spacing;
labelPos = [labelLeft labelBottom labelWidth textHeight];
t_9 = uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'Horiz','left', ...
'String','对象传递函数', ...
'Interruptible','off', ...
'BackgroundColor',[0.5 0.5 0.5], ...
'ForegroundColor','white');
%text(0.6,0.7,'对象传递函数:','fontsize',10);
textPos = [labelLeft+labelWidth labelBottom textWidth textHeight];
e_gs=uicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Position',textPos, ...
'Horiz','center', ...
'Background','white', ...
'Foreground','black', ...
'String','[0 1],[1 -1]');
%e_gs=uicontrol(gcf,'style','edit','background','white',...
% 'position',[0.78,0.675,0.15,0.05],'string','1,[1 -1]');
labelPos = [0.5 labelBottom-0.05 0.44 0.1];
t_11 = uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'Horiz','left', ...
'String',char('注:若对象传递函数为(a*s^2+b*s+c)/(d*s^2+e*s+f)','则输入[a b c],[d e f]'), ...
'Interruptible','off', ...
'BackgroundColor',[0.5 0.5 0.5], ...
'ForegroundColor','white');
labelBottom=top-13*textHeight-13*spacing;
labelPos = [labelLeft labelBottom labelWidth textHeight];
t_10 = uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'Horiz','left', ...
'String','采样周期(s)', ...
'Interruptible','off', ...
'BackgroundColor',[0.5 0.5 0.5], ...
'ForegroundColor','white');
%text(0.6,0.6,'采样周期(s):','fontsize',10);
textPos = [labelLeft+labelWidth labelBottom textWidth textHeight];
e_ts=uicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Position',textPos, ...
'Horiz','center', ...
'Background','white', ...
'Foreground','black', ...
'String','0.001');
%e_ts=uicontrol(gcf,'style','edit','background','white',...
% 'position',[0.78,0.575,0.15,0.05],'string','0.001');
b_1ok=uicontrol(gcf,'style','push','unit','normalized',...
'position',[0.4,0.04,0.2,0.1],'string','确定参数');
set(b_1ok,'callback',[...
'pmutation=str2num(get(e_pmutation,''string''));',...
'pcross=str2num(get(e_pcross,''string''));',...
'maxgen=str2num(get(e_maxgen,''string''));',...
'lchrom=str2num(get(e_lchrom,''string''));',...
'popsize=str2num(get(e_popsize,''string''));',...
'kpr=str2num(get(e_a,''string''));',...
'minkp=kpr(1);',...
'maxkp=kpr(2);',...
'kir=str2num(get(e_b,''string''));',...
'minki=kir(1);',...
'maxki=kir(2);',...
'kdr=str2num(get(e_c,''string''));',...
'minkd=kdr(1);',...
'maxkd=kdr(2);',...
'ts=str2num(get(e_ts,''string''));',...
'z=str2num(get(e_gs,''string''));',...
'gs=tf(z(1:order+1),[z(order+2:end)]);',...
'delete(b_1ok,e_a,e_b,e_c,e_gs,e_ts,r_pidorder1,r_pidorder2,r_pidorder3);',...
'delete(b_1pid,b_2ann,b_3f,f_2);',...
'delete(e_pmutation,e_pcross,e_maxgen,e_lchrom,e_popsize);',...
'delete(t_1,t_2,t_3,t_4,t_5,t_6,t_7,t_8,t_9,t_10,t_11);'...
'gaf',...
]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -