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.

 채택된 답변

MathWorks Support Team
MathWorks Support Team 2018년 12월 5일

1 개 추천

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.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Subsystems에 대해 자세히 알아보기

제품

릴리스

R13SP1

Community Treasure Hunt

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

Start Hunting!

Translated by