Is there a way to reduce compilation time for this segment?
조회 수: 2 (최근 30일)
이전 댓글 표시
tic
iscorr = 1;
myunc = zeros(1,length(Kurzschluss.Plateaus_I));
myfunction = '(X2/X1)*(sqrt(1 - X3^2/(X2^2 * X1^2)))';
for i=1:length(mystruct.Plateaus_I)
x1 = mystruct.Plateaus_I{1,i};
x2 = mystruct.Plateaus_U{1,i};
x3 = mystruct.Plateaus_P{1,i};
myunc(i) = calculateEndUncertainty_3(x1,x2,x3,iscorr,myfunction);
end
toc
댓글 수: 4
darova
2019년 9월 8일
You have a lot of eval() that is why script is slow
The function below depends on f(), temp(), temp_c1(), temp_c2()
Maybe you can attach whole your project? Any description?
채택된 답변
추가 답변 (1개)
Jackson Burns
2019년 9월 8일
Hi Souheil!
If you have access to the parallel computing toolbox, you can improve execution time with a parfor loop.
tic
iscorr = 1;
myunc = zeros(1,length(Kurzschluss.Plateaus_I));
myfunction = '(X2/X1)*(sqrt(1 - X3^2/(X2^2 * X1^2)))';
parfor i=1:length(mystruct.Plateaus_I)
x1 = mystruct.Plateaus_I{1,i};
x2 = mystruct.Plateaus_U{1,i};
x3 = mystruct.Plateaus_P{1,i};
myunc(i) = calculateEndUncertainty_3(x1,x2,x3,iscorr,myfunction);
end
toc
Other optimizations will likely come from improving your functions, such as calculateEndUncertainty_3. This page from MathWorks has some great advice on how to do this. I would reccomend looking at vectorization in particular, as MATLAB is extremely powerful when properly vectorized.
Hope this helps, good luck!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Parallel Computing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!