|
楼主 |
发表于 2007-4-7 21:18
|
显示全部楼层
代码很长啊
简单一下
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hk=findobj('tag','edit1');K=str2num(get(hk,'string'));
ht=findobj('tag','edit2');T=str2num(get(ht,'string'));
hlei=findobj('tag','popupmenu1');lei=get(hlei,'value');
axes(handles.axes1);
switch lei
case 1
a=[0,1;0,-1/T];b=[0,K/T]';ts=0.05;[phi,del]=c2d(a,b,ts);
xnl=[0 0]';xnlold=xnl;xlin=[0 0]';xlinold=xlin;t=0;u=4;tend=20;ks=2;gs=2;
while t<tend
t=[t t(length(t))+ts];enl=gs*(u-xnlold(1));elin=gs*(u-xlinold(1));
if enl>=ks,enlsat=ks;
elseif enl<=-ks,enlsat=-ks;
else enlsat=enl;
end
xnlold=phi*xnlold+del*enlsat;xnl=[xnl xnlold];
xlinold=phi*xlinold+del*elin;xlin=[xlin xlinold];
end
plot(xlin(1,:),xlin(2,:),'b'),grid on;hold on;plot(xnl(1,:),xnl(2,:),'r');
case 2
.....
plot(xlin(1,:),xlin(2,:),'b'),grid on;hold on;plot(xnl(1,:),xnl(2,:),'r');
case 3
......
plot(xlin(1,:),xlin(2,:),'b'),grid on;hold on;plot(xnl(1,:),xnl(2,:),'r');
case 4
......
plot(xlin(1,:),xlin(2,:),'b'),grid on;hold on;plot(xnl(1,:),xnl(2,:),'r');
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hk=findobj('tag','edit1');K=str2num(get(hk,'string'));;
ht=findobj('tag','edit2');T=str2num(get(ht,'string'));;
hlei=findobj('tag','popupmenu1');lei=get(hlei,'value');
axes(handles.axes1);
switch lei
case 1
a=[0,1;0,-1/T];b=[0,K/T]';ts=0.05;[phi,del]=c2d(a,b,ts);
xnl=[0 0]';xnlold=xnl;xlin=[0 0]';xlinold=xlin;t=0;u=4;tend=20;ks=2;gs=2;
while t<tend
t=[t t(length(t))+ts];enl=gs*(u-xnlold(1));elin=gs*(u-xlinold(1));
if enl>=ks,enlsat=ks;
elseif enl<=-ks,enlsat=-ks;
else enlsat=enl;
end
xnlold=phi*xnlold+del*enlsat;xnl=[xnl xnlold];
xlinold=phi*xlinold+del*elin;xlin=[xlin xlinold];
end
plot(t,xlin(1,:),'b'),grid on;hold on;plot(t,xnl(1,:),'r');
case 2
....
plot(t,xlin(1,:),'b'),grid on;hold on;plot(t,xnl(1,:),'r');
case 3
....
plot(t,xlin(1,:),'b'),grid on;hold on;plot(t,xnl(1,:),'r');
case 4
....
plot(t,xlin(1,:),'b'),grid on;hold on;plot(t,xnl(1,:),'r');
end |
|