- 积分
- 84
- 回帖
- 0
- 西莫币
-
- 贡献
-
- 威望
-
- 存款
-
- 阅读权限
- 5
- 最后登录
- 1970-1-1
该用户从未签到
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 张子富 于 2011-11-20 10:53 编辑
function [sys,x0,str,ts,simStateCompliance] = emf(t,x,u,flag)
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes;
case 3,
sys=mdlOutputs(t,x,u);
case 9,
sys=mdlTerminate(t,x,u);
case {1,2,4}
sys=[];
otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes(t,x,u)
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
%
x0 = [];
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts = [-1 0];
%
function sys=mdlDerivatives(t,x,u)
sys = [];
% end mdlDerivatives
%
%=============================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=============================================================================
%
function sys=mdlUpdate(t,x,u)
sys = [];
% end mdlUpdate
%
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u)
if(u>=0)&&(u<pi/3)
sys=[1 -1 -u*6/pi+1];
elseif(u>=pi/3)&&(u<2*pi/3)
sys=[1 u*6/pi-3 -1];
elseif(u>=2*pi/3)&&(u<pi)
sys=[-u*6/pi+5 1 -1];
elseif(u>=pi)&&(u<4*pi/3)
sys=[-1 1 u*6/pi-7];
elseif(u>=4*pi/3)&&(u<5*pi/3)
sys=[-1 -u*6/pi+9 1];
elseif(u>=5*pi/3)&&(u<2*pi)
sys=[u*6/pi-11 -1 1];
end
% end mdlOutputs
%
%=============================================================================
% mdlGetTimeOfNextVarHit
% Return the time of the next hit for this block. Note that the result is
% absolute time. Note that this function is only used when you specify a
% variable discrete-time sample time [-2 0] in the sample time array in
% mdlInitializeSizes.
%=============================================================================
%
%function sys=mdlGetTimeOfNextVarHit(t,x,u)
%sampleTime = 1; % Example, set the next hit to be one second later.
%sys = t + sampleTime;
% end mdlGetTimeOfNextVarHit
%
%=============================================================================
% mdlTerminate
% Perform any end of simulation tasks.
%==========================================================================
%===
function sys=mdlTerminate(t,x,u)
sys = [];
错误信息如下:
Output argument "sys" (and maybe others) not assigned during call to "D:\MATLAB\R2009a\toolbox\simulink\blocks\emf.m>mdlOutputs".
% end mdlTerminate |
|