duration to number(double)

771 views (last 30 days)
Any workaround to convert duration (seconds, hours, etc...) to a numeric value (double)

Accepted Answer

Steven Lord
Steven Lord on 28 Feb 2022
Use seconds, hours, etc. depending on how you want the duration array to be converted to a number.
d = duration(1, 2, 3)
d = duration
01:02:03
s = seconds(d)
s = 3723
m = minutes(d)
m = 62.0500
h = hours(d)
h = 1.0342
  5 Comments
Walter Roberson
Walter Roberson on 17 Oct 2022
When you apply minutes() or seconds() or days() or hours() to a double, then a duration object is created.
When you apply those functions to duration objects, double values are created.
For example
hours(days(7.2))
Juan Camilo Gómez Cadavid
if the argument to any of these functions : seconds, minutes, hours, etc... its a duration class, the output will be a numeric datatype (double)
Instead, if the argument to any of these functions is numeric, value will be converted to duration

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!