duration
在fixed-l长度的时间ength units
Description
The values in aduration arrayrepresent elapsed times in units of fixed length, such as hours, minutes, and seconds. You also can create elapsed times in terms of fixed-length (24-hour) days and fixed-length (365.2425-day) years.
Work with duration arrays as you would work with numeric arrays. You can add, subtract, sort, compare, concatenate, and plot duration arrays. Use duration arrays to simplify calculations on datetime arrays that involve time units such as hours and minutes.
Creation
You can create duration arrays that have specified time units using theyears
,days
,hours
,minutes
,seconds
, andmilliseconds
functions. For example, to create an array that has elapsed times of 1, 2, and 3 hours, use thehours
function.
D = hours(1:3)
D = 1×3 duration array 1 hr 2 hr 3 hr
You also can create a duration array using theduration
function, described below.
Syntax
Description
D = duration(
creates a duration array from numeric arrays containing the number of hours, minutes, and seconds specified byH,MI,S
)H
,MI
, andS
.
D = duration(H,MI,S,
adds milliseconds to the duration array, specified byMS
)MS
.
D = duration(
converts text that represents elapsed times into a duration array.TimeStrings
)TimeStrings
must represent times using either the'hh:mm:ss'
或the'dd:hh:mm:ss'
format.
D = duration(
converts text using the format specified byTimeStrings
,'InputFormat',infmt
)infmt
.
D = duration(___,'Format',displayFormat)
additionally specifies a display format forD
. This property changes the display ofD
, but not its values. You can use this syntax with any of the arguments from the previous syntaxes.
Input Arguments
Properties
Examples
Tips
For more information on functions that accept or return duration arrays, seeDates and Time.