Elapsed Time as a String (.mlx and .m files)

Formats the elapsedTime output of the toc command into a string. eg. 3601 seconds gets converted to '1 hour and 1 second'.
12 Downloads
Updated 16 Jul 2019

View License

The use of tic and elapsedTime=toc; commands gives the elapsed time in seconds. This function takes that value (or any other numeric or duration array value, provided it is in seconds) as input and accurately splits it into hours, minutes and seconds, and returns a formatted string that can be displayed on screen or inserted into a file. The formatted string is case dependent. For instance, if the input is 61 (seconds), the output is '1 minute and 1 second', while for an input of 3601 (seconds), the output is '1 hour and 1 second'.

Cite As

K Vijayanth Reddy (2025). Elapsed Time as a String (.mlx and .m files) (https://se.mathworks.com/matlabcentral/fileexchange/72152-elapsed-time-as-a-string-mlx-and-m-files), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2019a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0