Is there an Initialization block in Simulink?

1 view (last 30 days)
Is it possible to create a masked subsystem block that can be placed into a block diagram and serve as an Initialization block? In the masked initialization block, the user would enter the location and name of a script or function. This block would be added to the top-level of a Simulink model, and the specified script or function would be executed each time the model is opened or loaded. It would function similarly to the model initialization function callback under the "File -> Model Properties" menu item; however, it would be represented as a Simulink block.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 5 Dec 2018
Currently, there is no Initialization block in Simulink.
To work around this issue, you can create your own masked subsystem that prompts the user to enter a script name and then performs a specific callback routine, such as executing the script when the block diagram is loaded.
For example, the model test_init.mdl calls the simple script my_init.m, which allows a user to enter a script name. The script is executed before the simulation runs. In this case, the 'StartFcn' callback parameter is set, so the script is evaluated immediately before the simulation runs. You can use any of the callback routines you wish depending on when you want the user's script to be executed. More information on the model callback parameters is available in the documentation linked below:
The model test_init.mdl and the script my_init.m are available in the following Related Documents/Files.

More Answers (0)

Products


Release

R13SP1

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!