Guy on Simulink

Simulink & Model-Based Design

MATLAB系统块的方法

在最后在MATLAB系统块上发布,我试图为MATLAB中的系统对象and万博1manbetxenvironments. At the end, I finished with a quick example illustrating that System objects offer several methods to set up the properties of states and output signals of the system developed.

本周,客座博客作者Revathi Dukkipati将帮助我们仔细研究系统对象方法以及它们实施的顺序。

Guest Blogger Revathi Dukkipati

MATLAB中方法的时机

在创作系统对象时,要意识到的一件重要的事情是,您可以调用一些方法(for example处理数据),以及您实现的方法(for exampleStepimpl当您编写算法时).

步骤,与Stepimpl

要了解为什么您所调用的方法的名称与您实现的方法的名称之间有区别,我建议查看Methods Timing文档页面。您会找到如下图的图像,说明您可以调用哪些方法以及可以或需要实现的方法。

为了method, this looks like:

系统对象方法的时间安排

The methods shown with a green background can be implemented by the user. Except forStepimpl实现该算法的是,绿色中的其他方法具有内部默认实现。您只需要在默认值不适合您的应用程序时实现它们。白色显示的方法完全由MATLAB控制。

Simulink中方法的时间万博1manbetx

当通过MATLAB系统块中的Simulink中使用系统对象时万博1manbetx,重要的是要知道在编辑时间期间调用哪些方法,在模型汇编过程中调用了哪些方法,以及在模拟运行时每次调用哪些方法。

You can find an overview of this timing in the documentation page万博1manbetx映射到系统对象方法的Simulink发动机阶段

系统对象方法的时间安排

Let's look at those phases in more details with example.:

Model Edit phase:这是创建对象的地方。类似的方法getNumOutputsImplandgetNumInputsImpl需要呼吁模型编辑器万博1manbetxthe number of outputs and inputs of the block. Those methods are optional, you need to implement them only if your block has more than one input port and one output port.

Here is an example System object with two inputs and three outputs:

Example System Object with two inputs and three outputs

ModelCompile phase在模拟模型时,在模拟启动之前,Simulink需要确定所有信号的尺寸和其他属性。万博1manbetx对于其输入端口的属性,MATLAB系统块从连接到它的块中继承它们。对于输出端口,Simulink引擎可以尝试从输入端口万博1manbetx推断它们,或调用传播方法of your System object.

这些方法是从基类继承的matlab.system.mixin.propagatesand required when the output specificationscannot be inferred directly from the inputs。Even when output specifications can be inferred, adding the Propagation methods can improve the compilation time of your model since the time spent on inferring this data is saved.

Here is an example where the output has a dimension of five:

示例系统对象,其输出为5。

Model Execution phase:模型初始化完成后,算法中Stepimpl在每个步骤都被调用。如果块包含状态,我建议将Stepimpl分为两个功能:outputimpl在哪里计算输出信号的值,以及UpdateImplwhere you update the values of states internal to the block. Those two methods are provided bymatlab.system.mixin.Nondirect班级。

Here is an example implementing an accumulator, usingoutputimplandUpdateImpl

Example System Object using outputImpl and updateImpl to implement an accumulator.

Now it's your turn

Have you tried the MATLAB System block? Let us know what you think of the MATLAB System block by leaving a在这里评论
|

Comments

要发表评论,请单击here登录您的数学帐户或创建一个新帐户。