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

1 visualización (últimos 30 días)
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?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 11 de Nov. de 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:

Más respuestas (0)

Categorías

Más información sobre Programmatic Model Editing en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by