matlab中s函数level2,s函数level 2

本文详细介绍了MATLAB中的Level 2 M-file S函数,它与C-Mex S函数相似。主要讨论了如何使用setup方法设置S函数的基本属性,如端口数量、参数等,并展示了S函数的各个关键方法,包括CheckParameters、InitializeConditions、Start、Outputs、Update、Derivatives等。此外,还解释了如何注册和实现这些方法,以及如何处理输入输出端口的属性和数据类型。
摘要由CSDN通过智能技术生成

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'};

%

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值