Model callback fuctions simulink

来源:互联网 发布:相机特效软件 编辑:程序博客网 时间:2024/05/01 16:34

Creating Model Callback Functions

You can create model callback functions interactively or programmatically.Use theCallbacks pane of the model'sModel Properties dialog box (seeCallbacks 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.

ParameterWhen Executed

CloseFcn

Before the block diagram is closed. Any ModelCloseFcn and DeleteFcn callbacksset on blocks in the model are called prior to the model'sCloseFcn.TheDestroyFcn callback of any blocks in the modelis called after the model'sCloseFcn.

ContinueFcn

Before the simulation continues.

InitFcn

Called at start of model simulation.

PauseFcn

After the simulation pauses.

PostLoadFcn

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.

    Note  If you make structural changes with PostLoadFcn,the function does not set the modelDirty flagto indicate unsaved changes. You can close the model without beingprompted to save.

PostSaveFcn

After the model is saved.

PreLoadFcn

Before the model is loaded. Defining a callback routinefor this parameter might be useful for loading variables used by themodel.

    Note   In a PreLoadFcn callback routine, the get_param command does not return themodel's parameter values because the model is not yet loaded.

    In a PreLoadFcn routine, get_param returns:

    • The default value for a standard model parameter suchas solver

    • An error message for a model parameter added with add_param

    In a PostLoadFcn callback routine,however, get_param returns the model's parametervalues because the model is loaded.

PreSaveFcn

Before the model is saved.

StartFcn

Before the simulation starts.

StopFcn

After the simulation stops. Output is written to workspacevariables and files before theStopFcn is executed.