optimize code with multiple for loops

8 visualizaciones (últimos 30 días)
Anton Koroliov
Anton Koroliov el 7 de En. de 2019
Respondida: Jan el 7 de En. de 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

Respuestas (1)

Jan
Jan el 7 de En. de 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.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by