convert time in seconds after midnight to a certain interval

조회 수: 8 (최근 30일)
JARED VAHRENBERG
JARED VAHRENBERG 2020년 11월 8일
답변: per isakson 2020년 11월 9일
Given the time in seconds after midnight and an interval of what minutes it needs to be rounded to. So for example, if the output of like a datestr function gave 02:07 and my interval was 5 I would need it to be 02:05. How would I do this?
  댓글 수: 1
Mathieu NOE
Mathieu NOE 2020년 11월 9일
hi you need to make modulo(5) of the seconds
seconds_rounded = seconds - mod(seconds,5)

댓글을 달려면 로그인하십시오.

답변 (1개)

per isakson
per isakson 2020년 11월 9일
The script
%%
obj = duration( 0, 0, 2*3600+7*60 );
obj - mod( obj, minutes(5) )
outputs
ans =
duration
02:05:00
>>

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by