IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
find_varname.m
Go to the documentation of this file.
1 %>@ingroup codegen
2 %> @file
3 %> @brief Finds an unused variable name in the workspace
4 %
5 %> @param prefix
6 %> @return name_new
7 function name_new = find_varname(prefix)
8 i = 1;
9 while 1
10  name_new = sprintf('%s%02d', prefix, i);
11  if length(name_new) > 63
12  irerror(sprintf('Variable name ''%s'' is too big to add suffixes to it! Try renaming first.', prefix));
13  end;
14  if ~evalin('base', sprintf('exist(''%s'', ''var'')', name_new))
15  break;
16  end;
17  i = i+1;
18 end;
function irerror(in s)
function find_varname(in prefix)