How to check a signal value in the 'startFcn' for a Simulink model right before the model executes?

3 views (last 30 days)
I have a constant block in my model which acts as a source for a complex subsystem. My colleagues use this model. Now, I would like to throw an error and prevent my colleagues from running the model if the value of this constant block is 0. The problem I am facing is that I cannot use the output of the constant block as that would mean the model has started simulating. How can I meet this end goal?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 11 Nov 2021
Here is one solution for you:
  • The trick here is to read the block's "parameter" instead of the block's output "signal".
  • Note that a "signal" value can only be generated during simulation. So, as you rightly stated, reading a signal would mean starting the simulation.
  • You can use the "get_param" function to get the parameter values of the constant block in your model. For more information refer to this link:
  • Use "get_param" in the "startFcn" and show an error dialog if the value of the constant block is 0 using the "errordlg" function. Refer to the following link for more details:
Similar to obtaining values, you can also set values programmatically. Refer to the following link for more details:

More Answers (0)

Categories

Find more on Event Functions in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!