How to make MATLAB code execute faster

102 ビュー (過去 30 日間)
UTS
UTS 2014 年 2 月 2 日
コメント済み: shruti jain 2019 年 7 月 8 日
Hi,
How to make MATLAB code execute faster?
  2 件のコメント
Amit
Amit 2014 年 2 月 2 日
Are you asking for general tips?
shruti jain
shruti jain 2019 年 7 月 8 日
yes
i want to learn how to make a code

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

採用された回答

Andreas Goser
Andreas Goser 2014 年 2 月 2 日
Identify bottlenecks by using the Profiler tool within MATLAB.
Reflect on you really need that size of data and if the goal of your computation / project can maybe achieved by using less data.
Work with your IT department and MathWorks on finding ways for computing your stuff on a cluster.
  1 件のコメント
UTS
UTS 2014 年 2 月 3 日
Thank you very much.

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

その他の回答 (3 件)

Jan
Jan 2014 年 2 月 2 日
Use a clean and efficient code. E.g.:
  • pre-allocation
  • move repeated calculations out of the loops
  • prefer efficient operations, e.g. a multiplication is faster than a division, sqrt() is faster than ^0.5
  • Process the data in column direction, because it is faster to access elements, which are stored side by side in the memory
  • Vectorized code is often, but not always, faster in Matlab. This depends mainly on the´size of the required temporary arrays
  • Use an efficient structure to store your data. If you have to search in a list of strings, which is changed rarely only, using a sorted list can reduce the processing time massively, because this allows for a binary search
  • For large data sets, the RAM can be the limiting factor. Then a deeply nested struct might be better to keep the overview during programming, but one large cell can be faster for processing.
  • Never optimize prematurely. If you start programming with optimizing the code too much, the time required for debugging might explode. It is not useful to reduce the processing time by some seconds, if the debug time is some month. So start with creating a clean and correct code, take into account a efficient data structure, and finally optimize the bottlenecks only.

Walter Roberson
Walter Roberson 2014 年 2 月 2 日
Buy a faster computer.

Richard
Richard 2017 年 7 月 31 日
編集済み: Richard 2017 年 7 月 31 日

カテゴリ

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