How can I convert a time vector of HH:SS to a decimal?

조회 수: 15 (최근 30일)
Newbie
Newbie 2021년 8월 30일
답변: Steven Lord 2021년 8월 30일
I have a vector of time in format HH:SS in a table and I want to convert it to a decimal number.
For example:
03:30 = 3.5
04:45 = 4.75
How can I do that?
Thanks.
  댓글 수: 2
Jan
Jan 2021년 8월 30일
Are you sure the format is HH:SS and not HH:mm?
Newbie
Newbie 2021년 8월 30일
Sorry, you are right. It is HH:mm

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

채택된 답변

Steven Lord
Steven Lord 2021년 8월 30일
If you have them stored as a duration array just use the hours function.
du = duration({'03:30', '04:45'}, 'InputFormat', 'hh:mm')
du = 1×2 duration array
03:30:00 04:45:00
hours(du)
ans = 1×2
3.5000 4.7500

추가 답변 (1개)

Jan
Jan 2021년 8월 30일
v = datetime({'03:30', '04:45'}, 'InputFormat', 'HH:mm')
v = 1×2 datetime array
30-Aug-2021 03:30:00 30-Aug-2021 04:45:00
hour(v) + minute(v) / 60
ans = 1×2
3.5000 4.7500

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by