MATLAB: How to distinguish between the run options of a Signal Builder object in the StopFcn of a SIMULINK model

allcallbackplayallrunsignalbuildersimmodesimulinkstopfcn

I would like to be able to distinguish in the StopFcn of a SIMULINK model if the 'run' or the 'run all' option has been performed by a Signal Builder object.

Best Answer

Use the following code as the models StopFcn:
function my_fun
ud = get_param('test_sig1/Signal Builder','UserData');
ud = get(ud,'UserData');
runstate = ud.current.simMode
group = signalbuilder('test_sig1/Signal Builder','activegroup')
This will give a variable 'runstate' which is empty for the 'run' mode and 'PlayAll' for the 'run all' mode.
Additionally it gives a variable 'group' which contains information about the current active group of the Signal Builder.