Mercurial > hg > plml
diff matlab/db/uniquevar.m @ 0:0dd31a8c66bd
Initial check in to Mercurial, V.1
author | samer |
---|---|
date | Fri, 13 Jan 2012 15:29:02 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/matlab/db/uniquevar.m Fri Jan 13 15:29:02 2012 +0000 @@ -0,0 +1,19 @@ +function vn=uniquevar(x) +% uniquevar - Allocate a unique unused variable name +% +% uniquevar :: unit -> action string. +% uniquevar :: A~'initialied value' -> action string. +% +% If no initial value is given the variable is NOT allocated. +% There are up to 100000 variable names available. + + exists=1; + while exists, + vn=sprintf('t_%05d',floor(100000*rand)); + exists=evalin('base',['exist(''',vn,''',''var'')']); + end + if nargin>0, + assignin('base',vn,x); + end + +