필터 지우기
필터 지우기

Iterate through set of parameters for all possible combinations

조회 수: 24 (최근 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 CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by