Sometimes it’s something simple that ends up being the most handy. I can’t tell you how many times I’ve run a simulation whose base unit of time is seconds. For long simulations, you end up with some rather big numbers. At that point, it’s often more useful to think of the values in hours, days, and/or years. And so I end up at the MATLAB Command Window typing t/60/60/24…
MATLAB’s datetime data type has drastically simplified a lot of my time-related analysis tasks. However, I still find myself running my quick conversions on double-precision numbers. That’s where parseTime comes in. This no-frills function returns the equivalent years, weeks, days, hours, minutes, and seconds.
I’ll be adding this function to my path and expect to be invoking it regularly. The one thing I’d like added is support for arrays. It’s a small modification that most MATLAB programmers should be able to achieve on their own.
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.