How do you add parameter values to filename?
Afficher commentaires plus anciens
Hello,
I am running a program in which an analysis is done using a set of 3 parameter values. How can save the output so that it will incorporate the values of the parameters in the filename?
For example, rep=250 num=1000 dx=20
are the initial values of the parameters.
I would like the filename to be 'rep=250-num=1000-dx=20'. And then when I go into the program next and change the parameter values at the beginning, I would like the filename to automatically change to reflect that new set of parameter values. How do I automate this?
I am using dlmwrite to save the output. Thank you so much!
Réponses (2)
Star Strider
le 30 Août 2016
Modifié(e) : Star Strider
le 30 Août 2016
Use sprintf to create the file name, then write to it:
file_name = sprintf('rep=%.0f-num=%.0f-dx=%.0f.txt', rep, num,dx);
fido = fopen(file_name,'wt');
... CODE ...
fclose(fido);
Note: This is UNTESTED CODE. It should work if your operating system allows such characters in file names.
1 commentaire
Guillaume
le 30 Août 2016
If the numbers are integer, %d is a better format than %.0f
Guillaume
le 30 Août 2016
param1 = 250; param2 = 1000; param3 = 20;
filename = sprintf('rep=%d-num=%d-dx=%d.txt', param1, param2, param3);
dlmwrite(fullfile(folder, filename), somematrix);
Catégories
En savoir plus sur Workspace Variables and MAT Files dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!