Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to stop a Simulink simulation when a certain condition is met?

Assume that you have a Simulink simulation where a certain signal is first positive and after some time t in a given interval, it becomes negative. Your goal is to find the zero-crossing.

A first approach would be to plot the signal over the given interval, save it and calculate the zero-crossing.

When repeating this simulation numerous times for varying parameters, it would be beneficial to be able to stop the simulation after the signal has become negative. Then there is already enough information for the calculation of the zero-crossing in Matlab. How could you do that?

like image 556
Karlo Avatar asked Oct 20 '25 17:10

Karlo


2 Answers

Yes, use the Stop Simulation block with the appropriate logical input to the block:

enter image description here

like image 142
am304 Avatar answered Oct 22 '25 13:10

am304


You can use an if / else block to control the flow in the Simulink model. In the if / else block, you can choose the condition if u > 0, continue as normal if it's true, and use the else-option to bypass the rest of the flow you would otherwise run. For instance jump directly to the scope.

enter image description here

like image 25
Stewie Griffin Avatar answered Oct 22 '25 13:10

Stewie Griffin