What are Some General Tips for Making a Simulink model itself more efficient?

4 visualizzazioni (ultimi 30 giorni)
For MATLAB, there's a general rule of trying to vectorize operations to make MATLAB more efficient, and a few other general ways to make MATLAB code run faster.
In Simulink, I'm aware of Model level ways to make things more efficienct (step time changes, disabling zero crossing detection). However, oftentimes I can't use these genral tips - my step size is already on Auto, or I have the maximum step size I can use and get accurate results. Sometimes turning off the zero crossing detection gives me wild, unreleastic results. Also, oddly, sometimes disabling the zero crossing detection has made it run slower.
This question is not asking about those - I don't want to know how to run the existing model more efficiently. I'm asking about how to design the model itself to be more efficient. What are better / more efficient methods?
I'm using the Profiler and it's identifying blocks that are really inefficient, but I don't know what to do to make them more efficient.
Here are a few specific questions I have - but would appreciate any additional insight someone can offer:
  1. What is more efficient - multiplying a signal with a Boolean value determined by comparing another signal to a constant, or using a switch block with that comparison as the control input?
  2. What is more efficient if you only need to limit one side of a signal but not both (Min or Max Limit)? A Saturation block with Max as Inf (or Min as -Inf) or an individual Min (or Max) block?
  3. I need scopes to view the results of my simulation, but they seem to be slowing it down... is there a more efficient way to use them? (I know not to have one open while running the simulation, that definitely slows it down)
  4. Follow on to #3 - if I sometimes need scopes for debugging, but not in the final model, how can I easily switch them in and out? I could comment them out, I suppose, but I would prefer if I could use some sort of debug parameter on/off to do it.
  5. Is it more/same/less efficient to use individual blocks vs. built-in block functions for some things? For example, using the "Add Constant" or "Increment Real World" blocks vs. separate constant and sum blocks, using "Gain" block vs. separate constant and product blocks, etc.
  6. Does using Goto/From instead of directly connecting effect efficiency? (I'm guessing no from profiler information)

Risposte (1)

Prateekshya
Prateekshya il 5 Set 2023
As per my understanding you want to know the efficient methods to design a model. This is a very subjective question and depends on the model you want to design.
  1. Since multiplication is a basic arithmetic operation and "switch" block involves additional control logic and branching, multiplying a signal with a Boolean value determined by comparing another signal to a constant is generally more efficient.
  2. If you need to limit only one side of a signal, then using an individual "min" or "max" block is more efficient.
  3. You may try plotting the signals in MATLAB whenever possible instead of opening a "scope".
  4. You can use the Simulink variant subsystems. Create a variant subsystem that contains the "scope" block and another variant subsystem without the "scope" block. Use a variant control parameter to switch between the two subsystems, enabling or disabling the "scope" as needed.
  5. Built-in block functions combine multiple operations into a single block, reducing the overall computational load and improving efficiency. Hence these are more efficient compared to individual blocks.
  6. The use of “Goto”/ “From” blocks does not significantly impact efficiency in terms of simulation performance. However, excessive use of “Goto”/ “From” blocks can make the model harder to understand and maintain.
I hope that helps!

Categorie

Scopri di più su Programmatic Model Editing in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by