Creating Model Callback Functions
You can create model callback functions interactively or programmatically.Use theCallbacks pane of the model'sModel Properties dialog box (see Callbacks Pane) to create model callbacks interactively. Tocreate a callback programmatically, use theset_param commandto assign a MATLAB expression that implements the function tothe model parameter corresponding to the callback (seeModel Callback Functions).
For example, this command evaluates the variable testvar whenthe user double-clicks the Test block inmymodel:
set_param('mymodel/Test', 'OpenFcn', testvar)
You can examine the clutch system (sldemo_clutch.mdl)for routines associated with many model callbacks. This model definesthe following callbacks:
-
PreLoadFcn
-
PostLoadFcn
-
StartFcn
-
StopFcn
-
CloseFcn
Model Callback Functions
The following table describes callback functions associatedwith models.
Parameter | When Executed | |
---|---|---|
Before the block diagram is closed. Any ModelCloseFcn and DeleteFcn callbacksset on blocks in the model are called prior to the model'sCloseFcn.The DestroyFcn callback of any blocks in the modelis called after the model'sCloseFcn. | ||
Before the simulation continues. | ||
Called at start of model simulation. | ||
After the simulation pauses. | ||
After the model is loaded. Defining a callback routinefor this parameter might be useful for generating an interface thatrequires that the model has already been loaded. | ||
After the model is saved. | ||
Before the model is loaded. Defining a callback routinefor this parameter might be useful for loading variables used by themodel.
| ||
Before the model is saved. | ||
Before the simulation starts. | ||
After the simulation stops. Output is written to workspacevariables and files before theStopFcn is executed. |