How to reduce computation time in a code with multiple nested loops and if statements
조회 수: 5 (최근 30일)
이전 댓글 표시
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
답변 (1개)
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.
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!