필터 지우기
필터 지우기

automatically index .fig files

조회 수: 3 (최근 30일)
Wouter
Wouter 2014년 4월 23일
답변: Jan 2014년 4월 23일
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)

채택된 답변

Jan
Jan 2014년 4월 23일
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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 23일
for k=1:10
filename=sprintf('file%d.fig',k)
%do your plot and save your figure
end
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 23일
Can you clarify?
Wouter
Wouter 2014년 4월 23일
done

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by