automatically index .fig files

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)

 Respuesta aceptada

Jan
Jan el 23 de Abr. de 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

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 23 de Abr. de 2014

0 votos

for k=1:10
filename=sprintf('file%d.fig',k)
%do your plot and save your figure
end

3 comentarios

Wouter
Wouter el 23 de Abr. de 2014
I don't want to run this function a specific amount of times in a loop, it's more like I run it today, do some other matlab stuff and later on I decide to run it again with different parameters.
Azzi Abdelmalek
Azzi Abdelmalek el 23 de Abr. de 2014
Can you clarify?
Wouter
Wouter el 23 de Abr. de 2014
done

Iniciar sesión para comentar.

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 23 de Abr. de 2014

Respondida:

Jan
el 23 de Abr. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by