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 Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by