Main Content

Model, Block, and Port Callbacks

Execute code for modeling events such as opening a model

Callbacks are a powerful way to customize the behavior of a Simulink® model. Use callbacks to execute MATLAB® code in response to specific actions, such as opening a model or stopping a simulation. Each callback corresponds to a specific action. You specify the MATLAB code that a callback executes. When the corresponding action occurs, Simulink executes the callback code.

For example, the code that you specify for the PreLoadFcn model callback executes before the model loads. You can provide code for PreLoadFcn that loads the variables the model uses into the MATLAB workspace.


Simulink.AnnotationCreate and specify properties of text, image, and area annotations
getCallbackAnnotationGet annotation executing callback


Callback ButtonExecute MATLAB code using button