Model callbacks execute at specified action points, for example after you load or save the
model. You can set most of the same callbacks for libraries. Only the callbacks that can
execute for a library are available to set. For example, you cannot set the
InitFcn callback for a library, which is called as part of simulation,
because you cannot simulate a library.
In the Simulink® Editor, open the Property Inspector. Select View > Property Inspector.
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.
In the box, enter the functions you want the callback to perform.
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 clears the MATLAB workspace, including the variables created by the model A
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.
If a model references multiple instances of the same model in normal mode, callbacks execute for each instance.