MATLAB: How to tell if the InitFcn callback is being called from a model “Play” or an “Update Diagram” command or button-press in Simulink 7.4 (R2009b)

callbackinitfcninitializingsimulinkupdate

My model has an InitFcn callback that performs an action. I wish this action to be different based on whether the InitFcn was called from an update diagram (CTRL-D), or from model simulation as it is normally called before the StartFcn callback.

Best Answer

The Simulation Parameter 'SimulationStatus' can be used in Simulink 7.4 (R2009b) to determine the simulation status information, and perform the subsequent InitFcn actions. In the InitFcn callback, the following sample code illustrates how this can be achieved:
mode= get_param(gcs,'SimulationStatus');
switch mode
case 'initializing'
myInitFcnCallbackFromSim; % call appropriate user-defined script

case 'updating'
myInitFcnCallbackFromUpdate; % call appropriate user-defined script
end