How to iterate through every combination of user's choice of parameters?

4 次查看(过去 30 天)
I am scripting a parameter study in which the user identifies model parameters to vary as well as that parameter's values, for example:
parameterList(1).name = 'patientWeight' ;
parameterList(1).value = 100:25:300 ;
parameterList(2).name = 'dosage' ;
parameterList(2).value = 1000:1000:50000 ;
I want to perform a model run for all combinations of parameter values. Iterating is easy if the chosen parameters are the same for each study:
for iWeight = 1:length(parameterList(1).value)
for iDosage = 1:length(parameterList(2).value)
% Perform simulation and save results
end
end
But here the parameters and their values differ each time the script is run (next time, user might specify 'patientAge', 'numberOfDoses', and 'yearsOfTreatment'). How do I generate all combinations of parameters values from a changing list? (Would eventually like to use the parallel processing toolbox, if that is relevant.)

回答(1 个)

K E
K E 2012-4-5
From the file exchange, allcomb works perfectly:
allcomb(parameterList.value)
And I learned that I was looking for a 'cartesian product'.

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by