Speed up matlab program with .dll file

13 ビュー (過去 30 日間)
Tuan
Tuan 2012 年 11 月 13 日
Hi all,
I have a Matlab code with 4 for loops, and 1000 iterations for each loop. This code takes time and I would like to speed it up. Since the code can not be transformed into a vectorized version, so I think about converting M-Files to stand-alone applications (.dll for example). But I'm not sure if this can really make the execution faster. So if you have some experience about this, please share it to me.
By the way, if you know a easy method to convert a M-Files to a .dll file, can you tell me. Thank you in advance for your help.
Best regards,
Tuan
  2 件のコメント
Kaustubha Govind
Kaustubha Govind 2012 年 11 月 13 日
編集済み: Kaustubha Govind 2012 年 11 月 13 日
Please follow Jan's suggestions about whether your MATLAB code will be faster if compiled into C code, but just wanted to give you a heads up that one suggested way of accelerating MATLAB code is to generate a MEX-function from it using MATLAB Coder.
Tuan
Tuan 2012 年 11 月 13 日
This is very useful to me. Thank Kaustubha Govind.

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2012 年 11 月 13 日
Without seeing the code, we cannot guess, if a compiled version will be faster. Usually a compilation does not lead to substantially accelerations, while an optimized code or a manual creation of a Mex file will.
Please post the relevant parts of the code with typical input values. If we can run it, I assume we find some improvements.
  3 件のコメント
Jan
Jan 2012 年 11 月 13 日
Where do I find the "second 3 for loops to calculate Q"? This is quite a big piece of code and without helpful comments it is impossible to keep the overview. Some of the lines are monsters and splitting them to smaller parts as well as using temporary variables for repeatedly calculated values would increase the code but most of all improve the readability.
Tuan
Tuan 2012 年 11 月 13 日
Dear Jan Simon,
Sorry about my fuzzy code. I have reedited the code as your suggestion by preserving the main part that I'm worry about (see above section). The "3 for loops " is in the StaLaw3DFuncDelTRpRuStra function. A new value of Q is reused as input of trapz(), so a vectorized version of for loop is impossible. So, any way to speed up the program? Thank you!
Tuan

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by