This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Model Callbacks

Create Model Callbacks

  1. In the Simulink® Editor, open the Property Inspector. Select View > Property Inspector.

  2. With no selection at the top level of your model, in the Properties tab, in the Callbacks section, select the callback you want to set.

  3. In the box, enter the functions you want the callback to perform.

To create a model callback programmatically, use the set_param function to assign MATLAB® code to a model callback parameter. See Model Callback Parameters

The execution of callbacks for model referencing reflects the order in which the top model and the model it references execute their callbacks. For example, suppose:

  • Model A references model B.

  • Model A has a PostLoadFcn callback that creates variables in the MATLAB workspace.

  • Model B has a CloseFcn callback that clears the MATLAB workspace.

Simulating model A triggers rebuilding the referenced model B.

When Simulink rebuilds model B, it opens and closes model B and invokes the model B CloseFcn callback. CloseFcn clears the MATLAB workspace, including the variables created by the model A OpenFcn callback.

Instead of using a CloseFcn callback for model B, you can use a StopFcn callback in model A to clear the variables used by the model from the MATLAB workspace.

Model Callback Parameters

 Model Loading and Closing Callback Parameters

 Model Saving Callback Parameters

 Model Simulation Callback Parameters

Related Topics

Was this topic helpful?