MATLAB Answers

How to execute subsystem once at startup

29 views (last 30 days)
Sarah on 30 Oct 2017
I am trying to figure out how to do the Simulink equivalent of the Arduino 'void setup' in my program. For my program I want to have a startup mechanism to test my physical system, but it only needs to run once when the program is started. How would I go about doing this?


Sign in to comment.

Answers (1)

Madhu Govindarajan
Madhu Govindarajan on 30 Oct 2017
Simulink works on time, so it looks like you need to 1) read the clock time of the simulation model using the clock block - 2) Use this to enable an enabled subsystem at the appropriate time - 3) Put all your contents that can make the system startup inside this enabled subsystem. 4) Write logic that will disable the subsystem at the appropriate time.
Of course, there could be other possible workarounds.


Andrew Tilmouth
Andrew Tilmouth on 16 Oct 2018
If you have an atomic sub system which is set to a sample time of 0.02 and the clock is placed inside this system (connected to an If block checking for u1 == 0 and then to an If action subsystem containing the blocks that you want to run once) this will give the error shown below:- But it's not possible to change the clock sample time, there is no option to do that. How can this problem be solved, I am using 2013a so I do not have the new Initialize block although I am not sure if it is designed for that purpose anyway.
Any help would be appreciated, there is plenty of ECU code that needs to only run once at start up, this is a common requirement that needs to be modelled.
'ModelY/Clock' has an invalid sample time of [0, 0]. Periodic atomic subsystem 'ModelX' may contain only blocks that have constant (inf), inherited (-1), or periodic (0.02) sample times. To resolve this issue, try to change the sample time with one of the following: - Configuring the block 'ModelY/Clock' to inherit the sample time - Configuring the subsystem 'ModelX' to inherit the sample time. If you cannot change the block sample time, remove the problem block from the subsystem.
Madhu Govindarajan
Madhu Govindarajan on 16 Oct 2018
Maybe you can share a simpler version of your model to help me understand the issue better and then I can help.
MathWorks Technical Support might be a better resource regardless :)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by