setting up code to run matrix of parameter values
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I've written the code I've put below to run two functions sequentially. I'm trying to see what the effect of changing the parameters I've made global is on the output of the function, so I'd like to set the code up such that it will run combinations of the parameters' possible values. Preferably, I'd love it if it would run all of the possible permutations at once and put them into a .csv file, but that may be too complicated, so running the combinations in sets put into a .csv file would work well too. I've put all their possible values in matrices below, but I have no idea how to go about setting up a for loop so that it will run permutations of these values. As of now, I can get one set of parameter values to successfully run with the final values of the sets of equations be put into a .csv file. Any help would be much appreciated!
global F_1 F_2 R_R1 R_R2 V_1 V_2
%flow rates
F_1 = 0.25 %[0.25 0.5 1.25 2.5];
F_2 = 0.25 %[0.25 0.5 1.25 2.5];
%resource
R_R1 = 1e-5 %[3e-7 1e-5];
R_R2 = 1e-5 %[3e-7 1e-5];
%culture vessel volume
V_1 = 0.5 %[0.25 0.5];
V_2 = 0.5 %[0.25 0.5];
for i=1
soloalgae
tworesource_soloalgae_algaedaphnia
end
global equil
csvwrite('MATLAB.csv',equil,0,0)
0 commentaires
Réponse acceptée
Walter Roberson
le 26 Mai 2011
global F_1 F_2 R_R1 R_R2 V_1 V_2
global equil
F1list = [0.25 0.5 1.25 2.5];
F2list = [0.25 0.5 1.25 2.5];
R1list = [3e-7 1e-5];
R2list = [3e-7 1e-5];
V1list = [0.25 0.5];
V2list = [0.25 0.5];
[F1grid, F2grid, R1grid, R2grid, V1grid, V2grid] = ...
ndgrid(F1list, F2list, R1list, R2list, V1list, V2list];
N = numel(F1grid);
equils = cell(N,1);
for K = 1:N
F_1 = F1grid(K);
F_2 = F2grid(K);
R_R1 = R1grid(K);
R_R2 = R2grid(K);
V_1 = V1grid(K);
V_2 = V2grid(K);
soloalgae
tworesource_soloalgae_algaedaphnia
equils{K} = equil;
end
After that the task just becomes one of writing out all the values of the cell matrix equils. You did not indicate the type or shape of equil, and you did not indicate how you wanted the results to be written out relative to each other. (Do the results include the input parameters? If not then you would want the inputs written too so you know what you are looking at.)
csvwrite('MATLAB.csv', cell2mat(equils));
might be enough.
3 commentaires
Walter Roberson
le 27 Mai 2011
Replace
equils{K} = equil;
with
equils{K} = [F_1,F_2,R_R1,R_R2,V_1,V_2,equil];
There is no apparent way to prevent csvwrite from overwriting the data, so I suggest that you use dlmwrite() directly (csvwrite() calls dlmwrite() to do the actual work) using the '-append' flag of dlmwrite().
Plus de réponses (1)
Clemens
le 27 Mai 2011
I would do that by nested for loops:
global F_1 F_2 R_R1 R_R2 V_1 V_2
global equil
datamat = [];
for F_1 = [0.25 0.5 1.25 2.5]
for F_2 = [0.25 0.5 1.25 2.5]
for R_R1 = [3e-7 1e-5]
for R_R2 = [3e-7 1e-5]
for V_1 = [0.25 0.5]
for V_2 = [0.25 0.5]
soloalgae
tworesource_soloalgae_algaedaphnia
datamat = [datamat; [F_1,F_2,R_R1,R_R2, V_1,V_2,equil]];
end,end,end,end,end,end
gives you a nice datamat in the format of the penultimate line. Write with
csvwrite('result.csv',datamat)
Voir également
Catégories
En savoir plus sur Large Files and Big Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!