Main Content

S功能Examples

These examples show you how to work with a variety of S-functions or programs that use S-functions, including C/C++ S-functions, Fortran S-functions, S-function Builder, Level 2 MATLAB®S-functions, and Blockset Designer. Each section explains how to open the files and what is in them. These are good places to continue to develop an understanding S-functions after learning the basics. These do not represent all the examples available for S-functions, but a relevant subsection.

访问s功能示例

Most of the S-function examples are run throughsfundemos。This example library contains S-function models and is grouped by coding type, such as C S-functions or C++ S-functions.

sfundemos:

  1. 在MATLAB命令窗口中,输入sfundemos

    S功能示例库打开。

    Each block represents a category of S-function examples.

  2. 双击一个类别以显示其包含的示例。例如,单击C文件

  3. Double-click a block to open and run the example that it represents.

阅读下一章时,检查一些样本S功能可能会有所帮助。示例的代码存储在MATLAB根文件夹下的以下文件夹中。

MATLABcode

toolbox/simulink/simdemos/simfeatures

C,C ++和Fortran代码

toolbox/simulink/simdemos/simfeatures/src

Level-2 MATLAB S-Function Examples

TheMatlabroot/toolbox/simulink/simdemos/simfeaturesfolder (打开) contains many Level-2 MATLAB S-functions. Consider starting off by looking at these files. For more on Level-2 MATLAB S-functions, see写2级MATLAB S命令

文件名 Model Name Description
msfcn_dsc.m msfcndemo_sfundsc1 用继承的示例时间实现S功能。
msfcn_limintm.m MSFCNDEMO_LIMINTM 实现连续有限的集成器,其中输出由下层和上限界定,并包括初始条件。
msfcn_multirate.m msfcndemo_multirate 实施多室系统。
msfcn_times_two.m msfcndemo_timestwo 实现S函数,使其输入加倍。
msfcn_unit_delay.m msfcndemo_sfundsc2 Implement a unit delay.
msfcn_varpulse.m msfcndemo_varpulse 通过调用可变脉冲宽度生成器set_paramfrom within a Level-2 MATLAB S-function. Also demonstrates how to use custom set and get methods for the blockSimState
MSFCN_VS.M msfcndemo_vsfunc 实现可变样本时间块,其中第一个输入延迟了第二个输入确定的时间。

C S-Function Examples

TheMatlabroot/toolbox/金宝appsimulink/simdemos/simfeatures/srcfolder (打开) contains examples of C MEX S-functions, many of which have a MATLAB S-function counterpart. The C MEX S-functions are listed in the following table. For more on C S-functions, seeC/C++ S-Function Basics使用S功能构建器自动构建S函数

文件名 Model Name Description
csfunc.c sfcndemo_csfunc Implement a continuous system.
dlimintc.c 没有可用的模型 Implement a discrete-time limited integrator.
dsfunc.c sfcndemo_dsfunc Implement a discrete system.
limintc.c 没有可用的模型 Implement a limited integrator.
混合M.C sfcndemo_mixedm 实现由单位延迟(1/z)的连续集成器(1/s)组成的混合动力系统。
mixedmex.c sfcndemo_mixedmex Implement a hybrid dynamic system with a single output and two inputs.
slexQuantizeSFcn.c sfcndemo_sfun_quantize Implement a vectorized quantizer. Quantizes the input into steps as specified by the quantization interval parameter,q
sdotproduct.c sfcndemo_sdotproduct Compute dot product (multiply-accumulate) of two real or complex vectors.
sfbuilder_bususage.c sfbuilder_bususage Access S-Function Builder with a bus input and output.
sfbuilder_movingaveration。c sfbuilder_movingaveration 使用简单的时间窗口移动平均Start终止
sftable2.c sfcndemo_sftable2 实现二维表查找。
sfun_atol.c sfcndemo_sfun_atol Set different absolute tolerances for each continuous state.
sfun_cplx.c sfcndemo_cplx 使用一个输入端口和一个参数添加复杂的数据以进行S功能。
sfun_directlook.c 没有可用的模型 Implement a direct 1-D lookup.
sfun_dtype_io.c sfcndemo_dtype_io Implement an S-function that uses Simulink®data types for inputs and outputs.
sfun_dtype_param.c sfcndemo_dtype_param Implement an S-function that uses Simulink data types for parameters.
sfun_dynsize.c sfcndemo_sfun_dynsize 实施动态大小的输出。
sfun_errhdl.c sfcndemo_sfun_errhdl Check parameters using themdlCheckParametersS-function routine.
sfun_fcncall.c sfcndemo_sfun_fcncall 在第一个和第二个输出元素上执行功能通话子系统。
sfun_frmad.c sfcndemo_frame Implement a frame-based A/D converter.
sfun_frmda.c sfcndemo_frame Implement a frame-based D/A converter.
sfun_frmdft.c sfcndemo_frame Implement a multichannel frame-based Discrete-Fourier transformation (and its inverse).
sfun_frmunbuff.c sfcndemo_frame 实现基于框架的非封底块。
sfun_multiport.c sfcndemo_sfun_multiport 配置多个输入和输出端口。
sfun_manswitch.c 没有可用的模型 Implement a manual switch.
sfun_matadd.c sfcndemo_matadd Add matrices in an S-function with one input port, one output port, and one parameter.
sfun_multirate.c sfcndemo_sfun_multirate 演示如何指定基于端口的样本时间。
sfun_port_constant.c sfcndemo_port_constant Demonstrate how to specify constant port-based sample times.
sfun_port_triggered.c sfcndemo_port_triggered Demonstrate how to use port-based sample times in a triggered subsystem.
sfun_runtime1.c sfcndemo_runtime 实现所有可调参数的运行时参数。
sfun_runtime2.c sfcndemo_runtime Register individual run-time parameters.
sfun_runtime3.c sfcndemo_runtime 注册对话框参数作为运行时参数。
sfun_runtime4.c sfcndemo_runtime 实现运行时参数作为多个对话框参数的函数。
sfun_zc.c sfcndemo_sfun_zc Demonstrate use of nonsampled zero crossings to implementABS(U)。该S函数旨在与可变步骤求解器一起使用。
sfun_zc_sat.c sfcndemo_sfun_zc_sat 证明饱和度为零。
sfun_zc_cstate_sat.c sfcndemo_sfun_zc_cstate_sat Implement a continuous integrator with saturation limits and zero-crossing detection.
sfun_integrator_localsolver.c sfcndemo_sfun_localsolver Demonstrate a continuous integrator where the continuous states are solved using a separate local solver instead of that used by the model.
sfun_angle_events.c sfcndemo_angle_events Implement a method for robust and efficient detection of a rotating body crossing specified angles.
sfun_angle_events.c 没有可用的模型 演示角度检测并结合状态流®to schedule function calls.
sfunmem.c sfcndemo_sfunmem 实施一个综合步骤延迟并保持内存功能。
simomex.c sfcndemo_simomex

实现由状态空间方程描述的单输入,两输出状态空间动态系统:

dx/dt = Ax + Bu y = Cx + Du
在哪里xis the state vector,u是输入的向量,yis the vector of outputs.

stspace.c sfcndemo_stspace 实施一组状态空间方程。您可以使用S功能块和掩码设施将其变成新的块。此示例MEX文件执行与内置状态空间块相同的功能。这是MEX文件的一个示例,其中输入,输出和状态的数量取决于从工作区传递的参数。
stvctf.c sfcndemo_stvctf Implement a continuous-time transfer function whose transfer function polynomials are passed in via the input vector. This is useful for continuous time adaptive control applications.
stvdtf.c sfcndemo_stvdtf 实施一个离散的时间传输函数,其传输函数多项式通过输入向量传递。这对于离散时间自适应控制应用很有用。
stvmgain.c sfcndemo_stvmgain 实施时间变化的矩阵增益。
table3.c 没有可用的模型 实现3D查找表。
timestwo.c sfcndemo_timestwo Implement a C MEX S-function that doubles its input.
vdlmintc.c 没有可用的模型 实施离散的时间矢量有限积分器。
vdpmex.c sfcndemo_vdpmex Implement the Van der Pol equation.
vlimintc.c 没有可用的模型 Implement a vectorized limited integrator.
vsfunc.c sfcndemo_vsfunc Illustrate how to create a variable sample time block. This block implements a variable-step delay in which the first input is delayed by an amount of time determined by the second input.
sfun_pwm.c sfcndemo_pwm Illustrate how to create a controllable sample time block.
sfun_d2c sfcndemo_d2c 说明如何将离散输入信号转换为平滑的连续输出信号

Fortran S-Function Examples

下表列出了在Matlabroot/toolbox/金宝appsimulink/simdemos/simfeatures/srcfolder (打开)。有关Fortran S功能的更多信息,请参阅创建2级fortran s功能

文件名 Model Name

Description

sfun_atmos.c
sfun_atmos_sub.F
sfcndemo_atmos Calculate the 1976 standard atmosphere to 86 km using a Fortran subroutine.

C++ S-Function Examples

The following table lists sample C++ S-functions available in theMatlabroot/toolbox/金宝appsimulink/simdemos/simfeatures/srcfolder (打开)。For more on C++ S-functions, seeC/C++ S-Function Basics使用S功能构建器自动构建S函数

文件名 Model Name Description
sfun_counter_cpp.cpp sfcndemo_counter_cpp Store a C++ object in the pointers vectorPWORK
sfbuilder_permute.cpp sfbuilder_permutation 实现排列通过调用外部的c++一堂课ses using Start and Terminate.
sfbuilder_linfilt.cpp sfbuilder_upsampling 用C ++ STL算法实现线性过滤,以提高符号波。

在一个项目中组织S功能

下面的示例显示了如何将S功能伪像安排到项目中。这是使用“模块设计器”功能完成的。有关区块设计师的更多信息,请参阅创建一个模块项目

文件名 Description
slexBlocksetDesignerExample 使用模块设计师将S功能伪像组织到一个单个项目中。

See Also

|||

相关话题