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

조회 수: 1 (최근 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
MathWorks Support Team 2021년 11월 11일
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