How to measure elapsed time in hh:mm:ss?

35 次查看(过去 30 天)
Hi,
till now I measured elapsed time with:
tic;
% some code here
datestr(toc/86400,'HH:MM:SS')
Matlab R2022b says "datestr" is not recommended anymore. So how can I now convert timer-value (in seconds) to "hours-minutes-seconds"?

回答(2 个)

Stephen23
Stephen23 2023-1-30
编辑:Stephen23 2023-1-30
You can do this with SECONDS(), but then it requires two lines. Here is a simple solution on one line:
tic
..
dur = duration(0,0,toc)

Kunal Kandhari
Kunal Kandhari 2023-1-30
Hi you can use of seconds function:
tic;
s = seconds(toc/86400);
s.Format = 'hh:mm:ss'
Hope this helps!
  1 个评论
Stephen23
Stephen23 2023-1-30
The output of TOC is already in seconds... so dividing by the number of seconds in one day is not useful here.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by