Iterate through set of parameters for all possible combinations

13 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by