I cannot evaluate "pauseFcn" callback by using "sim" command

2 次查看(过去 30 天)
Hello, I'm having issues with Simulink callbacks. I'm using MATLAB 2019a.
I have a Simulink model. I am adding a listener to an output of that model by using startFcn callback. I am expecting the model to pause when the output takes a specific value. I am implementing this algorithm inside the listener's callback function.
When I try this from Simulink by using "Run" button, the results are as expected, i.e., model pauses and the calculations are done within the "pauseFcn". But when I use "sim('myModel')" command in MATLAB, Simulink does not evaluate the pauseFcn even if the condition is triggered.
In addition, I traced the callbacks from command window. I see that, when I use 'Run' button, pauseFcn callback is triggered properly and commands in it are evaluated. However, when I use sim command, I see that pauseFcn callback is not triggered.
What should I do to make the model work corretly with sim command? Is this a bug?

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2024-4-20
A few things.
  1. Try SimOut=sim(). It used to be, that if there is no return variable specified, then the simulation won't log the output after the simulation is completed. Many questions have been asked before when user could not find the expected output in the base workspace after the simulation is completed. The latest document on sim() doesn't seem to show this tip or limitation anymore but try it anyway.
  2. It sounds like your listener is MATLAB code executed by the StartFcn callback. Depending on the methods used, I am not sure if it is able to monitor the output while the simulation is running using sim(). I know the simulation output data logging when using sim() is done when the simulation is completed, not while the simulation is running.
  3. You could consider adding this monitoring and action into the model using the Assertation block. https://www.mathworks.com/help/releases/R2019a/simulink/slref/assertion.html
  4. Or start from here to see if you can find a better way. https://www.mathworks.com/help/simulink/ug/accessing-block-data-during-simulation.html

类别

Help CenterFile Exchange 中查找有关 Model, Block, and Port Callbacks 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by