matlabundocumented-behavior

matlab: get variable creation time


I want to renew a variable if it is outdated - obviously this could be done with storing its creation time.

However - is there a (possilby undocumented) way of figuring out WHEN a variable in workspace was declared?


Solution

  • No, there is no way to know when a variable was created. People have explored the array metadata in detail, and nobody has found any indication of creation time stamps.

    Furthermore, such a data field has no uses in general, and therefore are unlikely to be implemented, as a time stamp would just take up memory without providing a benefit.

    For the very few cases where such a time stamp would be useful, I’d recommend creating a class that behaves like a normal numeric array, but additionally carries a time stamp.