家伙在simu金宝applink上

金宝app基于模型的设计

Methods of the MATLAB System Block

In the lastpost on MATLAB System block, I tried to provide a basic introduction toSystem Objects in MATLAB金宝app环境。最后,我完成了一个快速示例,说明系统对象提供了几种方法来设置已开发系统的状态和输出信号的属性。

This week, guest blogger Revathi Dukkipati will help us get a closer look atSystem object methods和the sequence in which they are implemented.

客座博客Revathi Dukkipati

Timing of methods in MATLAB

When authoring System objects, one important thing to realize is that there are methods that you can call (例如stepto process data), and the methods that you implement (例如stepImplwhen you write your algorithm)。

step, versus stepImpl

To understand why there is a difference between the name of the method you call and the name of the method you implement, I recommend looking at the方法计时documentation page. You will find images like the following illustrating which methods you can call, and which methods you can or need to implement.

For thestep方法,这看起来像:

Timing of System objects methods

用户可以实现带有绿色背景的方法。除了stepImplwhich implements the algorithm, the other methods in green have an internal default implementation. You only need to implement them if the default is not appropriate for your application. The methods shown in white are completely controlled by MATLAB.

Timing of Methods in Simulink

When using a System object in Simulink through the MATLAB System block, it is important to know which methods are called during edit time, which methods are called during the model compilation and which methods are called every time step when the simulation runs.

您可以在文档页面中找到此计时的概述Simulink Engine Phases Mapped to System Object Methods:

Timing of System objects methods

让我们以示例中的更多细节来看看这些阶段。

模型编辑阶段:This is where the object is created. Methods likegetNumOutputsimplgetNumInputsimpl需要要求Simulink编辑器知道块的输出和输入的数金宝app量。这些方法是可选的,只有当您的块具有多个输入端口和一个输出端口时,才需要实现它们。

这是一个示例系统对象,具有两个输入和三个输出:

带有两个输入和三个输出的示例系统对象

模型编译阶段:When simulating a model, before the simulation can start, Simulink needs to determine the dimensions and other properties of all signals. For the properties of its input ports, the MATLAB system block inherits them from the blocks connected to it. For the output ports, the Simulink engine can try to infer them from the input ports, or call thepropagation methods您的系统对象。

These methods are inherited from the base classmatlab.system.mixin.Propagates当输出规格时需要不能直接从输入中推断。即使可以推断出输出规格,添加传播方法也可以改善模型的汇编时间,因为在推断此数据上所花费的时间已保存。

这是一个示例,其中输出的尺寸为五:

Example System Object with an output of dimension 5.

模型执行阶段:一旦模型初始ization is completed, the algorithm instepImplis called at every step. If the block contains states, I recommend separating thestepImplinto two functions:outputImplwhere you compute the values of output signals, andupdateImpl您更新块内部状态值的位置。这两种方法由matlab.system.mixin.Nondirectclass.

这是一个实现累加器的示例,使用outputImplupdateImpl

使用outputimpl和UpdateImpl实现累加器的示例系统对象。

现在轮到你了

您是否尝试过MATLAB系统块?让我们知道您对MATLAB系统块的看法comment here
|

评论

To leave a comment, please click这里to sign in to your MathWorks Account or create a new one.