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 其他一些设置
%%
%% 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'};
%