optimize code with multiple for loops

조회 수: 5 (최근 30일)
Anton Koroliov
Anton Koroliov 2019년 1월 7일
답변: Jan 2019년 1월 7일
My task is to fit experimental data with equation containing 7 unknow parameters. So I can check all posible parameter values my code contain 7 for loop, if parameter range is big calculations took a lot of time. Is there a way to get rid of for loops and speed up my calculations?
here is idea of my code. Each parameter range can be difrent
index = 1;
for par_1 = 1:0.1:10
for par_2 = 1:0.1:10
for par_3 = 1:1:10
for par_4 = 1:1:5
for par_5 = 1:1:100
for par_6 = 1:0.1:10
for par_7 = 1:0.1:100
% huge euation calculation
% comparison with experiment data
index = index+1
% save parameter values for futher use
table(index,1) = par_1;
table(index,2) = par_2;
table(index,3) = par_3;
table(index,4) = par_3;
table(index,5) = par_5;
table(index,6) = par_6;
table(index,7) = par_7;
end
end
end
end
end
end
end

답변 (1개)

Jan
Jan 2019년 1월 7일
It depends on the magic parts "% huge euation calculation" and "% comparison with experiment data" if the loops can be avoided. Only posting the loops and just a rought comment for the actual calculations is not enought to suggest a solution.
Currently the only hint is to pre-allocate the output and not to use "table" as a name of a variable, because it is an important Matlab function.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by