MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

d =


48:30:45 23:30:45


By default, a duration array displays in the format, hours:minutes:seconds. Change the
display format of the duration by changing its Format property. You can display the
duration value with a single unit, such as hours.


d.Format = 'h'


d =


48.512 hrs 23.512 hrs


You can create a duration in a single unit using the seconds, minutes, hours, days, or
years functions. For example, create a duration of 2 days, where each day is exactly 24
hours.


d = days(2)


d =
2 days


You can create a calendar duration in a single unit of variable length. For example, one
month can be 28, 29, 30, or 31 days long. Specify a calendar duration of 2 months.


L = calmonths(2)


L =
2mo


Use the caldays, calweeks, calquarters, and calyears functions to specify
calendar durations in other units.


Add a number of calendar months and calendar days. The number of days remains
separate from the number of months because the number of days in a month is not fixed,
and cannot be determined until you add the calendar duration to a specific datetime.


L = calmonths(2) + caldays(35)


L =
2mo 35d


Add calendar durations to a datetime to compute a new date.


t2 = t + calmonths(2) + caldays(35)


Represent Dates and Times in MATLAB
Free download pdf