Slow simulation because of matlab function block which interact with python code.

13 次查看(过去 30 天)
My simulation model has a Matlab function block which sends some data to a model in Python and receives the answer of the model to use it in simulation. My problem is my simulation is running so slow, however, when I increase the sample time of that Matlab function block it runs faster but at the cost of low accuracy! What is your suggestion to simulate without changing the sample time of that MATLAB function block?

采纳的回答

SOUMNATH PAUL
SOUMNATH PAUL 2023-11-15
Hi Mohammed,
To my understanding your simulation runs slowly with the current setup, impacting efficiency and increasing the sample time of the MATLAB function block improves speed but sacrifices accuracy. Your concern is regarding the trade-off between simulation speed and accuracy when adjusting the sample time of the MATLAB function block. Here are few suggestions that can be followed:
  1. Focus on identifying and eliminating redundant operations, streamline loops, and consider vectorized computations. Additionally, you can leverage MATLAB's built-in functions and features that can enhance code efficiency for improved simulation performance.
  2. Explore parallel computing in MATLAB to distribute computations and enhance speed. You can find more information in the following link : https://in.mathworks.com/products/parallel-computing.html
  3. Use MATLAB's profiling tools to identify and address code bottlenecks. You can find more information in the following link : https://in.mathworks.com/help/matlab/matlab_prog/profiling-for-improving-performance.html
  4. You can consider using MATLAB Compiler to convert code into a standalone executable for faster execution.
  5. Experiment with different solver options and parameters in Simulink.
  6. Check if certain aspects of the simulation model can be simplified without sacrificing accuracy.
Hope it helps!
Regards,
Soumnath

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by