Iterate through set of parameters for all possible combinations

13 ビュー (過去 30 日間)
rbharrs
rbharrs 2021 年 10 月 26 日
コメント済み: Duncan Po 2021 年 10 月 26 日
I have a set of 4 parameters that I'm going to use to test an algorithm. I'm trying to created nested for loops to iterate through each possible combination (each parameter has 5 values to test).
But I also want to export this as a table, where later there will also be results from each combination (row).
This is what I have so far :
K = [0.9 0.99 0.999 0.9999 0.99999];
L = [1e-2 1e-4 1e-6 1e-8 1e-10];
maxAccelArr = [];
tauArr = [];
stayAliveArr = [];
PTerminateArr = [];
for i=1 : 5
maxAccel=9.8*i; %acceleration
maxAccelArr(i) = maxAccel;
for j= 100 :100: 500
tau=j; %maneuver time
tauArr(j/100) = tau;
for k = 1 : length(K)
PStayAlive= K(k); % stay alive
stayAliveArr(k) = PStayAlive;
for l = 1:length(L)
PTerminate=L(l); % termination probability
PTerminateArr(l) = PTerminate;
end
end
end
end
% save paremeter testing values as a table
parameterTest = table(maxAccelArr.', tauArr.', stayAliveArr.', PTerminateArr.');
filename = 'parameter_test.xlsx';
writetable(parameterTest, filename);
But this is generating a table with only 5 rows each, not all possible combinations. Any tips on how to accomplish this?
  1 件のコメント
Duncan Po
Duncan Po 2021 年 10 月 26 日
There is another thread about this topic. You should be able to find a solution there:
https://www.mathworks.com/matlabcentral/answers/98191-how-can-i-obtain-all-possible-combinations-of-given-vectors-in-matlab

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by