tomwalters@0: % support file for 'aim-mat' tomwalters@0: % tomwalters@0: % This file is included as part of the 'aim-mat' distribution package bleeck@3: % (c) 2011, University of Southampton bleeck@3: % Maintained by Stefan Bleeck (bleeck@gmail.com) bleeck@3: % download of current version is on the soundsoftware site: bleeck@3: % http://code.soundsoftware.ac.uk/projects/aimmat bleeck@3: % documentation and everything is on http://www.acousticscale.org bleeck@3: tomwalters@0: tomwalters@0: function filename=get_new_filename(prefix,extension); tomwalters@0: % gives back the a name of a file that does not exist yet that has a number tomwalters@0: % one higher then the highest number that exist with that name tomwalters@0: % example: newfile('new','mat') gives back new1.mat tomwalters@0: % again: newfile('new','mat') gives back new2.mat new3.mat etc tomwalters@0: tomwalters@0: if nargin<2 || strcmp(extension,''); tomwalters@0: extension='*'; tomwalters@0: else tomwalters@0: if isempty(strfind(extension,'.')) tomwalters@0: extension=['.' extension]; tomwalters@0: end tomwalters@0: end tomwalters@0: searchstr=sprintf('allfiles=dir(''%s*%s'');',prefix,extension); tomwalters@0: eval(searchstr); tomwalters@0: tomwalters@0: if length(allfiles)==0 tomwalters@0: filename=[prefix '1' extension]; tomwalters@0: return tomwalters@0: end tomwalters@0: tomwalters@0: lastfileinfo=allfiles(end); tomwalters@0: lastfile=lastfileinfo.name; tomwalters@0: nr1=strfind(lastfile,prefix)+length(prefix); tomwalters@0: nr2=strfind(lastfile,extension); tomwalters@0: nr=str2num(lastfile(nr1:nr2)); tomwalters@0: tomwalters@0: newnumber=nr+1; tomwalters@0: filename=sprintf('%s%d%s',prefix,newnumber,extension);