フィルターのクリア

How to reduce computation time in a code with multiple nested loops and if statements

5 ビュー (過去 30 日間)
Askeladden2
Askeladden2 2020 年 7 月 12 日
回答済み: Srivardhan Gadila 2020 年 7 月 15 日
Dear all Community members,
I have written a code that involves multiple nested loops and several if statements which require many iterations. The matrices involved are big that does the computations time consuming. I want to reduce the computation time, either by vectorization or "rewriting" the nested loops.
I have attached an excerption of the code by simplyfing the mathematical operations.
I appreciate all help and tips.
Thanks in advance!

回答 (1 件)

Srivardhan Gadila
Srivardhan Gadila 2020 年 7 月 15 日
Vectorized code often runs much faster than the corresponding code containing loops (Vectorization).
In addition to that I would suggest you to refer to parfor, Parallel for-Loops (parfor) & Parallel Computing Toolbox.
If you have a gpu then you can make use of GPU Computing.
Note that there would be some additional time consumed to start parallel pool of workers in case of parfor. In the case of GPU computing some additional time would be consumed when data is transferred to GPU from MATLAB & vice-versa.

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by