Iterate through set of parameters for all possible combinations
14 views (last 30 days)
Show older comments
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 Comment
Duncan Po
on 26 Oct 2021
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
Answers (0)
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!