MATLAB: How to modify the model callback functions programmatically

simulink

How can I modify the Simulink model callback functions programmatically?

Best Answer

You may use the "set_param" function.
Here is the example code about how to change the 'InitFcn' programmatically using one of our shipped example 'vdp.slx':
>> vdp
>> set_param('vdp','InitFcn','a = 2;')
or
>> vdp
>> set_param(gcs,'InitFcn','a = 2;')
Please reference our documentation page for more details about the 'set_param' function and Model Callbacks: