How computationally intensive are switch case action blocks in Simulink?

So I need to switch between different linear models based on a switch condition and computational load is a big concern for my application. I was wondering, does anyone know how costly it is to implement these switch case action blocks?:
https://www.mathworks.com/help/simulink/slref/switchcaseactionsubsystem.html
I was thinking of having a ton of them in the model but only selecting a few based on a switch condition. Like a switch case in code, does having more of these switch action blocks not matter in terms of the computational load of checking them? Like if I had 190 different switch action blocks, the simulink simulation wouldnt check all 190 action blocks to see if it would run them, and rather it would just directly go and simulate the ones the switch case selects? I was hoping this would be the case, but I would much rather check before implementing the 190ish switch case action blocks I need.

 Accepted Answer

Yes. More cases will not increase the computation load. Only the activated cases will be executed. It is called the Condtionally Executed Subsystem.
However, 190ish cases are extream. I would not implement like that in Simulink. Explain the need. There might be a better solution.

3 Comments

I have 190 different linear models whose linearization points collectively discretize my operating conditions, and I want to select the single output from only the one which has its linearization conditions closest to my operating conditions.
For computational efficiency, I am not running all 190 models simultaneously. However, these are estimation based models so before I select one of them for their answer, they should be running for a bit so that the estimation converges to an accurate solution. So in order to make sure the nearest condition output switching goes smoothly, I also need to run 3 "nearby" models whose operating conditions are next closest to my current operating condition. This is so that if my operating condition continuously varies and I need to slect a nearby model's output, I can sort of be sure that it has run for a bit and its estimation has had time to converge to be more accurate. So just to summarize, at all times I usually need to be running 4 out of the 190 linear models at a time while only selecting the output of 1 of them, and which models are selected for running or for their output varies based on my current operating condition.
This need to simulate not only the nearest model but also the other three next nearest models has made things pretty hard to implement for me. I had an idea where I would detect when I switched the 4 model "region" I need to run, and in this idea I would have just four switch action subsystems whose parameters would update once whenever a switch in region was detected. However, there are issues where I need to keep track of which one is the actual nearest system on region switch (because I need to keep its simulation running in its simulation block) which complicates indexing the four blocks, and while that can be addressed I am mainly concerned about whether I miss a "region" switch during the parameter switching, which would I think cause things to fall apart since if I miss a "region" switch, the simulations running would not be correct since an update to the parameters only occurs in this idea when I detect the rising signal of a "region" switch. Sorry if I am not explaining things clearly.
I know theres probably a way better method, and please let me know if you know of one for this case since as it is I need to do like 190 different data entries, but I settled on just having 190 different switch action blocks which greatly simplifies the thought I need to put into this. Also, thanks for the help again!
"at all times I usually need to be running 4 out of the 190 linear models at a time while only selecting the output of 1 of them, and which models are selected for running or for their output varies based on my current operating condition."
I think I understand the need.
I would suggest using a MATLAB Function block. Basically, you would "code" whatever you want to do. Implementing 190ish LTIs using block diagram would be hard to manage.
Oh wow, that seems like exactly what I need. Thank you so much, you just saved me like 2 hours of data entry.

Sign in to comment.

More Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Tags

Asked:

on 9 Apr 2024

Commented:

on 9 Apr 2024

Community Treasure Hunt

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

Start Hunting!