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

2 次查看(过去 30 天)
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?

采纳的回答

MathWorks Support Team
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:

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by