I am currently modelling the resistive response of a material upon stretching it. I have about 10 parameters, and I would like to make a sweep study on some of them, sometimes sweeping 1, 2, or maybe 4 (etc.) parameters without having to modify my code too much.
MWE:
The study function
function result = mystudy(a,b,c,d,e)
result = a+b+c+d+e
end
The main
%study of the electric response of a material.
%parameters:
a = 3;
b = 5;
c = 11:13; %sweeping c
d = 0:1; %sweeping d too
e = 25;
%code needed to achieve the following table:
parameter_table =
3 5 11 0 25
3 5 11 1 25
3 5 12 0 25
3 5 12 1 25
3 5 13 0 25
3 5 13 1 25
for num_study = 1:size(parameter_table,1)
parameters = { parameter_table(num_study,:) };
result = mystudy( parameters{:} );
end
The clear advantages of proceeding this way :
- I always have only 1 loop and don't need to nest-loop my study depending on how many parameters I want to sweep.
- It should be possible to launch a new study my simply modifying the entries under %parameters:
My only difficulty is to create the parameter_table, where each line is the set of parameters that will be used. Is there a smart way to make the table ?