MATLAB Answers


Speed up simulation

I've read some of the questions posted on mathworks regarding this subject, but still I want to speed up the simulation for example by 10 times or 100 times.
The reason to do this is because I'm using a signal builder with lots of values used for testing a model and writing the outputs in an excel and to do this for all the values would take about 7h...
Thanks in advance, Alex


Sign in to comment.

1 Answer

Answer by Kaustubha Govind on 26 Jun 2012
 Accepted Answer

There are several techniques for improving your Simulink model's performance. Please see these articles:
Also, you mentioned writing outputs to an Excel file - do you do this at the end of simulation or at each time step? I'm assuming you use the XLSWRITE command?


Alexandru on 26 Jun 2012
The inputs are always changing so yes I'm using a Level 2 S-Function to write the results with the XLSWRITE. But I could try to write the outputs in a cell array and write them at the end in the excel...
on 26 Jun 2012
You may also find this blog entry helpful for making sure you are not wasting time with the wrong step size,
Kaustubha Govind on 27 Jun 2012
Nice tip KE!
@Alexandru: XLSWRITE opens and closes the Excel file at each time step, which I suspect may be slowing down your simulation. You could try using the Simulink Profiler to see where the slowdown is coming from before investing in improving the Excel writing part. If that S-function turns out to be the culprit, what you need is to only open once, write all your data and close it. You can either do this in your S-function by controlling the Excel COM connection (relevant function is: so that you open the file in setup() and close in terminate(). Or if you prefer to stick with XLSWRITE, just do it at the end of simulation.

Sign in to comment.