automatically index .fig files

3 vues (au cours des 30 derniers jours)
Wouter
Wouter le 23 Avr 2014
Réponse apportée : Jan le 23 Avr 2014
I have a function that generates graphs which become saved in a .fig file. Now, I want to run this function multiple times with different parameters. Is it possible for matlab to save all these fig files(let's say file.fig, file(1).fig, file(2).fig) or will it overwrite the old one file.fig each time? I prefer not to put all the input arguments of my function in the name.
The function is called omegac4.m and has four input arguments(a cell array IN which defines initial conditions, wmin and wmax are doubles and a natural number N). I automatically put a scalar(IN{1}) in the name of the .fig file via sprintf. The program divides the [wmin,wmax] intervals in N steps w(n) and for each w I call a function vortex9(IN,w) I times(I define I in the beginning of my script, it's 10000 right now but it's possible I'll change it later on). For each w(n) I take the average of the I results of vortex9 and save them in v(n). At the end of omegac4 I write w(n) and v(n) in a txt-file(the new text is added to the old one at the bottom) and I make a plot of v as a function of w. I want to save this plot as a figure, and if I run omegac4 a second time (with the same IN{1}) I want to store the new plot, but don't lose the old one.
It's some kind of simulation dependent on random numbers, a run takes a couple of hours and afterwards I decide each time with which new parameters I want to run it (possibly the same)

Réponse acceptée

Jan
Jan le 23 Avr 2014
I assume, that you want to determine a new file name automatically. If you do not want to rely on tempname, which creates unique, but strange looking names, you require a dedicated function like this:
function Name = FindNewName(Folder, Pattern, Spec)
% Input:
% Folder: Folder name
% Pattern: File name with a star for the counter
% Spec: Number format for SPRINTF
% Example:
% FindNewName(cd, 'Figure*.fig', '%.3d')
List = dir(fullfile(Folder, Pattern));
Num = length(List) + 1;
Fmt = strrep(Pattern, '*', Spec);
Name = sprintf(Fmt, Num);
% Care for deleted files:
while exist(fullfile(Folder, Name), 'file')
Num = Num + 1;
Name = sprintf(Fmt, Num);
end

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 23 Avr 2014
for k=1:10
filename=sprintf('file%d.fig',k)
%do your plot and save your figure
end
  3 commentaires
Azzi Abdelmalek
Azzi Abdelmalek le 23 Avr 2014
Can you clarify?
Wouter
Wouter le 23 Avr 2014
done

Connectez-vous pour commenter.

Catégories

En savoir plus sur Timing and presenting 2D and 3D stimuli dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by