Model callback fuctions simulink

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.

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.The DestroyFcn 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.


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值