主要内容

蒙版回调代码

Add Mask Code

您可以使用MATLAB®代码以初始化掩码并绘制蒙版图标。由于代码的位置会影响模型性能,因此添加代码以反映所需的功能。

Purpose Add in Mask Editor 编程规范
Initialize the mask 初始化pane MaskInitialization范围
Draw mask icon Iconpane MaskDisplay范围
Callback code for mask parameters Parameters & Dialogpane MaskCallbacks范围

Execute Drawing Command

Place MATLAB code for drawing mask icons in the图标绘图命令section of theIconpane. Simulink®executes these commands sequentially to redraw the mask icon when:

  • Block is rendered first on the Mask Editor canvas.

  • Mask parameters and values that depend on drawing commands change.

  • Block appearance is altered due to rotation or other changes.

Note

Placing MATLAB code for drawing mask icons in the初始化section affects model performance. This behavior is because Simulink redraws the icon each time the masked block is evaluated in the model.

Execute Initialization Command

初始化commands for all masked blocks in a model run when you:

  • Update the diagram

  • 开始模拟

  • 启动代码生成

  • Apply mask changes

  • Change any of the parameters that define the mask, such asMaskDisplayMaskInitialization,using the Mask Editor orset_param.

  • Rotate or flip the masked block, if the icon depends on initialization commands.

  • 导致图标被绘制或重新绘制,并且图标图取决于初始化代码。

  • Change the value of a mask parameter by using the block dialog box orset_param.

  • Copy the masked block within the same model or between different models.

When you open a model, Simulink locates visible masked blocks that reside at the top level of the model or in an open subsystem.

Simulink only executes the initialization commands for these visible masked blocks if they meet either of the following conditions:

  • The masked block has icon drawing commands.

    Note

    Simulink does not initialize masked blocks that do not have icon drawing commands, even if they have initialization commands during model load.

  • The masked subsystem belongs to a library and has the允许库块修改其内容启用参数。

当您将模型加载到内存而不以图形方式显示内存时,没有初始化命令最初针对任何掩盖块运行。看加载模型load_systemfor information about loading a model without displaying it.

Note

The non-tunable parameters of a masked block are not evaluated if the model is already compiled (initialized).

执行回调代码

Mask parameter callback codes are executed in a temporary workspace and not in the base workspace. If you need a variable created in the callback to be available later(not during callback processing), you must explicitly assign those variables to the base workspace.

Simulink executes the callback commands when:

  • You open the mask dialog box. Callback commands execute sequentially, starting with the top mask dialog box.

  • You modify a parameter value in the mask dialog box and then change the cursor location. For example, you press theTabkey or click into another field in the dialog box after changing the parameter value.

  • You modify the parameter value by using theset_param命令,回调命令执行。

  • You modify the parameter value, either in the mask dialog box or usingset_param,和then apply the change by clickingApply或者好的. Mask initialization commands execute after callback commands. For more information, seeCode Pane.

  • You hover over a masked block to see the tool tip for the block, when the tool tip contains parameter names and values.

    Note

    如果出现块工具提示时,“蒙版”对话框打开了,请勿执行回调命令。

  • You update a diagram by pressingCtrl+d或者by clicking更新模型on theModelingtab in the Simulink Editor.

  • 如果您在不保存更改的情况下关闭掩码对话框,则依次执行参数的回调命令。

Note

Buttons on mask dialog box are unavailable when the callback code associated with the button is being executed.

有关相关的Simulin万博1manbetxk示例模型,请参见:

相关话题