optimize code with multiple for loops

8 Ansichten (letzte 30 Tage)
Anton Koroliov
Anton Koroliov am 7 Jan. 2019
Beantwortet: Jan am 7 Jan. 2019
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

Antworten (1)

Jan
Jan am 7 Jan. 2019
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.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by