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. |
创建模型回调函数
了解如何在Matlab中创建和配置模型回调函数,包括预加载、加载后、启动、停止等阶段的回调,以及如何通过参数设置实现特定行为。
3745

被折叠的 条评论
为什么被折叠?



