How to reduce computation time in a code with multiple nested loops and if statements
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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!
0 Commenti
Risposte (1)
Srivardhan Gadila
il 15 Lug 2020
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.
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.
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!