S函数模板——精选推荐

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

S函数模板
function [sys,x0,str,ts] = abs(t,x,u,flag)
%MIXEDM An example integrator followed by unit delay M-file S-function
% Example M-file S-function implementing a hybrid system consisting
% of a continuous integrator (1/s) in series with a unit delay (1/z).
%
% See sfuntmpl.m for a general S-function template.
%
% See also SFUNTMPL.
% Copyright 1990-2007 The MathWorks, Inc.
% $Revision: 1.28.2.1 $
% Sampling period and offset for unit delay.
switch flag
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0
[sys,x0,str,ts]=mdlInitializeSizes;
%%%%%%%%%%%%%%%
% Derivatives %
%%%%%%%%%%%%%%%
case 1
sys=mdlDerivatives(t,x,u);
%%%%%%%%%%
% Update %
%%%%%%%%%%
case 2,
sys=[];
%%%%%%%%%%
% Output %
%%%%%%%%%%
case 3
sys=mdlOutputs(t,x,u);
%%%%%%%%%%%%%
% Terminate %
%%%%%%%%%%%%%
case 9
sys = []; % do nothing
otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
% end mixedm
%
%============================================================================= % mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%============================================================================= %
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [0 0];
% end mdlInitializeSizes
%
%============================================================================= % mdlDerivatives
% Compute derivatives for continuous states.
%============================================================================= %
function sys=mdlDerivatives(t,x,u)
sys = 2;
% end mdlDerivatives
%
%============================================================================= % mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%============================================================================= %
% end mdlUpdate
%
%============================================================================= % mdlOutputs
% Return the output vector for the S-function
%============================================================================= %
function sys=mdlOutputs(t,x,u)
% Return output of the unit delay if we have a
% sample hit within a tolerance of 1e-8. If we
% don't have a sample hit then return [] indicating
% that the output shouldn't change.
sys =2* u;
% end mdlOutputs。

相关文档
最新文档