Tuesday, May 26, 2009

Matlab: generate unique ID number

To generate a unique ID number for e.g. a temporary file or seed for random number generator current date/time in milliseconds can be used. I matlab the only command that gives time in milliseconds is datestr with FFF input e.g. datestr(now,'MMSSFFF')

ans =

5139451
datestr(now,'MMSSFFF')

ans =

5140057

UID=datestr(now,'MMSSFFF')

UID =

5214981

Unfortunatly other commands such as cputime or now don't return time in milliseconds, which is not so good.