matlab中s函数level2,s函数level 2 function
msfuntmpl(block) 打%符号的全是注释都可⽆视的说,后⾯我会放上⽆注释版
%MSFUNTMPL A template for an M-file S-function
% The
M-file S-function is written as a MATLAB function with
the
% same name
as the S-function. Replace 'msfuntmpl' with the name
% of your
S-function.
%
% It should
be noted that the M-file S-function is very similar
% to
Level-2 C-Mex S-functions. You should be able to get
more
% information for each of the block methods by referring to
the
% documentation for C-Mex S-functions.
%
% Copyright
2003-2006 The MathWorks, Inc.
% $Revision: 1.1.6.13
$⽆视就可以了,但是得把msfuntmpl改成你⾃⼰的函数名
%%
%% The setup method is used to setup the basic attributes of
the 设置⽅法⽤来设定s函数的基本的属性,⽐如端⼝个数
%% S-function such as ports, parameters, etc. Do not add any
other
%% calls to the main body of the
function. %% setup(block); 调⽤setup函数,函数在后⾯定义,看见没函数主体就tm⼀个
%endfunction
%% Function: setup
=================================================== %% Abstract:
%% Set up the
S-function block's basic characteristics such as:
%% - Input
ports 输⼊个数
%% - Output
ports 输出个数
%% - Dialog
parameters 对话框参数
%% -
Options 其他⼀些设置
function怎么记忆%%
%% Required : Yes
%% C-Mex
counterpart: mdlInitializeSizes 这应该是在C-mex中对应的函数
%%
function
setup(block) 看见没,这⾥看是定义函数setup了
% Register number of ports
block.NumInputPorts =
1; 输⼊输出
block.NumOutputPorts = 1;
% Setup port properties to be inherited
or
dynamic 端⼝属性是继承还是动态
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
% Override input port properties
block.InputPort(1).DatatypeID =
0; %
double 预先定义数据类型,0代表double
block.InputPort(1).Complexity = 'Real';
% Override output port properties
block.OutputPort(1).DatatypeID = 0;%
double 同上
block.OutputPort(1).Complexity = 'Real';
% Register parameters
block.NumDialogPrms =
3; 对话框参数设置,这⾥有3个,分别是'Tunable','Nontunable','SimOnlyTunable' block.DialogPrmsTunable =
{'Tunable','Nontunable','SimOnlyTunable'};
% Register sample times
% [0
offset] : Continuous sample time
% [positive_num
offset] : Discrete sample time
%
% [-1,
0] : Inherited sample time
% [-2,
0] : Variable sample time
block.SampleTimes = [0
0]; 采样时间,[0,0],第⼀个0代表连续,第⼆个代表偏移量为0,上⾯是告诉你该怎么设置%%
-----------------------------------------------------------------
%% Options
%%
-
----------------------------------------------------------------
% Specify if Accelerator should use TLC
or call back into
% M-file
block.SetAccelRunOnTLC(false); 不知道这个TLC是⼲嘛的,以后再说
%%
-----------------------------------------------------------------
%% The M-file S-function uses an internal
registry for all
%% block methods. You should register all
relevant methods
%% (optional and required) as illustrated
below. You may choose
%% any suitable name for the methods and
implement these methods
%% as local functions within the same
file.
%%
-----------------------------------------------------------------
%%
-----------------------------------------------------------------
%% Register methods called during update
diagram/compilation
%%
-----------------------------------------------------------------
%%
%% CheckParameters:
%% Functionality : Called in order to allow validation of %% block's dialog parameters. User is
%% responsible for calling this method
%% explicitly at the start of the setup method
%% C-Mex
counterpart: mdlCheckParameters
%%
block.RegBlockMethod('CheckParameters',
@CheckPrms); 检查参数
%%
%% SetInputPortSamplingMode:
%% Functionality : Check and set input and output port %% attributes specifying if port is operating
%% in sample-based or frame-based mode
%% C-Mex
counterpart: mdlSetInputPortFrameData%% (Signal Processing Blockset is required in order to set a port
%% to be frame-based)
%%
block.RegBlockMethod('SetInputPortSamplingMode',
@SetInpPortFrameData);
%%
%% SetInputPortDimensions:
%% Functionality : Check and set input and optionally output %% port dimensions
%% C-Mex
counterpart: mdlSetInputPortDimensionInfo
%%
block.RegBlockMethod('SetInputPortDimensions',
@SetInpPortDims);
%%
%% SetOutputPortDimensions:
%% Functionality : Check and set output and optionally input %% port dimensions
%% C-Mex
counterpart: mdlSetOutputPortDimensionInfo
%%
block.RegBlockMethod('SetOutputPortDimensions',
@SetOutPortDims);
%%
%% SetInputPortDatatype:
%% Functionality : Check and set input and optionally output %% port datatypes
%% C-Mex
counterpart: mdlSetInputPortDataType
%%
block.RegBlockMethod('SetInputPortDataType',
@SetInpPortDataType);
%%
%% SetOutputPortDatatype:
%% Functionality : Check and set output and optionally input

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。