- 积分
- 67
- 回帖
- 0
- 西莫币
-
- 贡献
-
- 威望
-
- 存款
-
- 阅读权限
- 5
- 最后登录
- 1970-1-1
该用户从未签到
|
楼主 |
发表于 2009-6-16 09:32
|
显示全部楼层
function [sys,x0,str,ts] = torquecalc(t,x,u,flag)
%
% The following outlines the general structure of an S-function.
%
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u);
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
case 9,
sys=mdlTerminate(t,x,u);
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
%
function [sys,x0,str,ts]=mdlInitializeSizes
%
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [-1 0];
%
function sys=mdlDerivatives(t,x,u)
sys = [];
%
function sys=mdlUpdate(t,x,u)
sys = [];
%
function sys=mdlOutputs(t,x,u)
%
sudu=u(1);
sflux=u(2);
if (sudu<760)
% b=b+1;
a=0;
end
if (sflux==0||sflux==pi/3||sflux==2*pi/3||sflux==3*pi/3||sflux==4*pi/3||sflux==5*pi/3&&sudu>=750)
% b=b+1;
a=1;
end
%if(rem(x(1),2)==0)
% a=1;
%end
sys(1)=a;
%
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampleTime = 1; % Example, set the next hit to be one second later.
sys = t + sampleTime;
%
function sys=mdlTerminate(t,x,u)
sys = [];
% end mdlTerminate |
|