?? sfuntmpl.m
字號:
function [sys,x0,str,ts] = sfuntmpl(t,x,u,flag)
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
%%%%%%%%%%%%%%%
% Derivatives %
%%%%%%%%%%%%%%%
case 1,
sys=mdlDerivatives(t,x,u);
%%%%%%%%%%
% Update %
%%%%%%%%%%
case 2,
sys=mdlUpdate(t,x,u);
%%%%%%%%%%%
% Outputs %
%%%%%%%%%%%
case 3,
sys=mdlOutputs(t,x,u);
%%%%%%%%%%%%%%%%%%%%%%%
% GetTimeOfNextVarHit %
%%%%%%%%%%%%%%%%%%%%%%%
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
%%%%%%%%%%%%%
% Terminate %
%%%%%%%%%%%%%
case 9,
sys=mdlTerminate(t,x,u);
%%%%%%%%%%%%%%%%%%%%
% Unexpected flags %
%%%%%%%%%%%%%%%%%%%%
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
% end sfuntmpl
%
%==================================================
% mdlInitializeSizes
% Return the sizes, initial conditions,
% and sample times for the S-function.
%==================================================
%
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
% 該語句返回一個沒有經過初始化的sizes數組,此數組是
% s-function信息的載體。
% 根據s-function的實際情況及sizes數組各個字段的意義可以
% 對各字段進行賦值。
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 0;
sizes.NumInputs = 0;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
% at least one sample time is needed
sys = simsizes(sizes);
% 對sizes賦值完之后,再調用simsizes指令,將定義好的sizes
% 數組作為參數,并把結果返回給sys變量。
% 其實,simsizes(sizes)只是把sizes數組組成一個長度為6的
% 向量,因此完全可以用一條簡單的賦值語句代替上述賦值。
% sys=[0,0,0,0,1,1];
% 注意輸入的順序與上述字段順序相同。
% initialize the initial conditions
%
x0 = [];
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts = [0 0];
% end mdlInitializeSizes
%
%==================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%==================================================
%
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)
sys = [];
% 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 = [];
% end mdlTerminate
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -