设计目标:在鼠标拖动滑块的同时,观察到输出曲线的变化
代码如下,由于初学matlab,这是导师交给的任务,我实在不知道在s1=uicontrol这里面的回调函数该怎么写才能滑动滑块改变数值的同时让图片动起来,希望能指点一下
已写部分代码如下
```c++
clc
format long
a1=axes('Position',[0.4,0.55,0.4,0.35]);
a2=axes('Position',[0.4,0.10,0.4,0.35]);
% 主计算函数
fre=logspace(-4,7,256);
w = 2*pi*fre;
Kp = 3; % PID比例部分 1-10
Ki = 0.8; % PID积分部分 0.1-10
Kd = 0.3; % PID微分部分 0.1-10
Tf = 0.1; % 0.01-1
s=1j*w;
C=Kp+Ki./s+Kd.*s./(Tf.*s+1);
PID=20*log10(abs(C)); % 单位:度
Phase=rad2deg(angle(C)); % 单位:度
PID_AF=semilogx(fre,PID);
PID_PF=semilogx(fre,Phase);
% 画图的控制
title('PID Amplitude Frequency Characteristic','fontsize',12); %PID幅频特性
title('PID Phase Frequency Characteristic','fontsize',12); %PID相频特性
Pa=uicontrol(gcf,'style','text',...
'unit','normalized','position',[0.06,0.86,0.21,0.06],...
'BackgroundColor',0.7*[1,1,1],'ForegroundColor',[0.8,0.1,0.9],...
'string','kP: 0.01','fontsize',16,'fontname','times new roman');
s1=uicontrol(gcf,'style','slider',...
'unit','normalized','position',[0.06,0.76,0.21,0.04],...
'BackgroundColor',0.7*[1,1,1],'ForegroundColor',[0.1,0.1,0.9],...
'SliderStep',[0.01,0.01],'value',1/100,...
'callback',['L=get(s1,''value'')*100;',...
'set(Pa,''string'',[''Kp: '',num2str(L/10),''nm'']);',...
'C=Kp+Ki./s+Kd.*s./(Tf.*s+1);',...
'PID=20*log10(abs(C));Phase=rad2deg(angle(C));',...
]);
uicontrol(gcf,'style','text',...
'unit','normalized','position',[0.08,0.81,0.05,0.03],...
'BackgroundColor',0.7*[1,1,1],'ForegroundColor',[0.1,0.1,0.9],...
'string','0.01','fontsize',16,'fontname','times new roman');
uicontrol(gcf,'style','text',...
'unit','normalized','position',[0.24,0.81,0.05,0.03],...
'BackgroundColor',0.7*[1,1,1],'ForegroundColor',[0.1,0.1,0.9],...
'string','10','fontsize',16,'fontname','times new roman');
```