tomwalters@0
|
1 % support file for 'aim-mat'
|
tomwalters@0
|
2 %
|
tomwalters@0
|
3 % This file is included as part of the 'aim-mat' distribution package
|
bleeck@3
|
4 % (c) 2011, University of Southampton
|
bleeck@3
|
5 % Maintained by Stefan Bleeck (bleeck@gmail.com)
|
bleeck@3
|
6 % download of current version is on the soundsoftware site:
|
bleeck@3
|
7 % http://code.soundsoftware.ac.uk/projects/aimmat
|
bleeck@3
|
8 % documentation and everything is on http://www.acousticscale.org
|
bleeck@3
|
9
|
tomwalters@0
|
10
|
tomwalters@0
|
11 function filename=get_new_filename(prefix,extension);
|
tomwalters@0
|
12 % gives back the a name of a file that does not exist yet that has a number
|
tomwalters@0
|
13 % one higher then the highest number that exist with that name
|
tomwalters@0
|
14 % example: newfile('new','mat') gives back new1.mat
|
tomwalters@0
|
15 % again: newfile('new','mat') gives back new2.mat new3.mat etc
|
tomwalters@0
|
16
|
tomwalters@0
|
17 if nargin<2 || strcmp(extension,'');
|
tomwalters@0
|
18 extension='*';
|
tomwalters@0
|
19 else
|
tomwalters@0
|
20 if isempty(strfind(extension,'.'))
|
tomwalters@0
|
21 extension=['.' extension];
|
tomwalters@0
|
22 end
|
tomwalters@0
|
23 end
|
tomwalters@0
|
24 searchstr=sprintf('allfiles=dir(''%s*%s'');',prefix,extension);
|
tomwalters@0
|
25 eval(searchstr);
|
tomwalters@0
|
26
|
tomwalters@0
|
27 if length(allfiles)==0
|
tomwalters@0
|
28 filename=[prefix '1' extension];
|
tomwalters@0
|
29 return
|
tomwalters@0
|
30 end
|
tomwalters@0
|
31
|
tomwalters@0
|
32 lastfileinfo=allfiles(end);
|
tomwalters@0
|
33 lastfile=lastfileinfo.name;
|
tomwalters@0
|
34 nr1=strfind(lastfile,prefix)+length(prefix);
|
tomwalters@0
|
35 nr2=strfind(lastfile,extension);
|
tomwalters@0
|
36 nr=str2num(lastfile(nr1:nr2));
|
tomwalters@0
|
37
|
tomwalters@0
|
38 newnumber=nr+1;
|
tomwalters@0
|
39 filename=sprintf('%s%d%s',prefix,newnumber,extension);
|