How computationally intensive are switch case action blocks in Simulink?

17 views (last 30 days)
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

Fangjun Jiang
Fangjun Jiang on 9 Apr 2024 at 17:24
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
Fangjun Jiang
Fangjun Jiang on 9 Apr 2024 at 17:59
"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.
Vinh
Vinh on 9 Apr 2024 at 18:01
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)

Tags

Community Treasure Hunt

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

Start Hunting!