|
楼主 |
发表于 2007-5-12 15:46
|
显示全部楼层
把程序贴上来,希望有人能找出问题
function [sys,x0,str,ts]=area_sel(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]= mdlInitializeSizes;
case 2,
sys=[];
case 3,
sys=mdlOutputs(t,x,u);
case 4,
sys=[];
case 9,
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function[sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 2;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [];
function sys=mdIOutputs(t,x,u)
if(u(1)>0)
if(u(2)/u(1)<1/sqrt(3)&&u(2)/u(1)>-1/sqrt(3))
sys=1;
end
if(u(2)/u(1)>1/sqrt(3))
sys=2;
end
if(u(2)/u(1)<-1/sqrt(3))
sys=6;
end
end
if(u(1)<0)
if(u(2)/u(1)<-1/sqrt(3))
sys=3;
end
if(u(2)/u(1)<1/sqrt(3)&&u(2)/u(1)>-1/sqrt(3))
sys=4;
end
if(u(2)/u(1)>1/sqrt(3))
sys=5;
end
end
if(u(1)==0)
if(u(2)>0)
sys=3;
else
sys=6;
end
end |
|