How to use a variant sink depending on its input

I have a s-function and it has 6 outputs, the next step is to check is there a negtive in 6 outputs. If there is one negtive, the simulation should be stop. If there is not, the 6 outputs should be passed to next s-function to continue simulating. In this case, I choose a variant sink, one of the output connects to stop block and another connects to next s-function to continue simulating. The thing is how can I use variant sink depending on its input rather than a pre-defined varable.
The pic shows how I use the variant sink, but it has an error saying that both the h and y (two of the outputs of s-funtion) are not defined.
Thank you very much!

 Accepted Answer

I think the "Variant Sink" block is un-necessary. If you want to stop the simulation when any of the output goes nagative, then you need to feed (or with some pre-process first) the output to the Stop block all the time. So the Stop block is constantly checking the value and stop the simulation when the condition is met. At the same time, also feed the output to the next s-function.

6 Comments

Thank you for your answer,but I have tried this method at the first beginning showed in the pic.
I add another s-function to check whether the 6 outputs goes negtive using additional one output to express the state, if it is 1, the simulation should be stopped, if is 0, the other 6 outputs should be passed to next function.从.png
But the thins is, though first outputs is 1, the simulation do not stop and continue to pass the outputs to next.
Anyway, still many thanks.
Add a default Step function block and connect it to the Stop block and run simulation, you will see the simulation runs only to 1 second.
Yes, that is the default step function`s output turns from 0 to 1 at 1 second.
I understand you are talking about the time problem so I check my system and finding that, the next s-function and this s-function which has 6 outputs may be at the same simulation iter, so when the 1 pass to stop, at the same time, the six outputs contain a negtive are passed to next s-function and in there cause an error( becaues there is a sqrt operation in there).
so, I still need an operation to stop the simulation once the outputs contain a negative and can`t let them pass to next functino.
It would be easy in your "next s-function" to check for negative value and take any action, or simply do somthing to avoid errors. A separate logic and the Stop block can be used to stop the simulation. You can't really use Simulink to "Pass" or "Not Pass" data to downstreams. Most blocks run all the times and the input/output data needs to be there all the times. You could use a Switch block to pass different data depending on certain conditions.
Here is the whole logic, the turbine`s 6 outputs containing a negtive will lead to the next controller a complex. I have tried a check for conplex at controller, but it will leads to turibine a complex too. So I choose a variant to active only one route, either to pass variables or stop.
Still many thanks
Hi, I have solve this problem in Matlab rather than Simulink.
I use an ode45 to solve the turbine and control derivates, and ode45 has a Option. I can define an event in this option. When a complex event occurs, the ode45 can be stopped immediately。
Thank you very much for answering my problems!

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

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

Start Hunting!