필터 지우기
필터 지우기

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!

답변 (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 CenterFile Exchange에서 Loops 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