Asked by Souheil Araoud
on 8 Sep 2019

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

Answer by Jackson Burns
on 8 Sep 2019

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!

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## darova (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/479415-is-there-a-way-to-reduce-compilation-time-for-this-segment#comment_743461

## Souheil Araoud (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/479415-is-there-a-way-to-reduce-compilation-time-for-this-segment#comment_743478

## darova (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/479415-is-there-a-way-to-reduce-compilation-time-for-this-segment#comment_743483

## Souheil Araoud (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/479415-is-there-a-way-to-reduce-compilation-time-for-this-segment#comment_743490

Sign in to comment.