calmonths

Calendar duration in months

Description

example

M = calmonths(X) returns an array representing calendar months equivalent to the values in X.

  • If X is a numeric array, then M is a calendarDuration array with each element equal to the number of calendar months in the corresponding element of X.

  • If X is a calendarDuration array, then M is a double array with each element equal to the number of whole calendar months in the corresponding element of X.

Examples

collapse all

X = magic(4);
M = calmonths(X)
M = 4x4 calendarDuration
   1y 4mo      2mo      3mo   1y 1mo
      5mo     11mo     10mo      8mo
      9mo      7mo      6mo       1y
      4mo   1y 2mo   1y 3mo      1mo

Create an array of calendar durations. Then, convert each value to the equivalent number of whole calendar months.

X = calmonths(15:17) + caldays(8) + hours(1.2345)
X = 1x3 calendarDuration
   1y 3mo 8d 1h 14m 4.2s   1y 4mo 8d 1h 14m 4.2s   1y 5mo 8d 1h 14m 4.2s

M = calmonths(X)
M = 1×3

    15    16    17

Input Arguments

collapse all

Input array, specified as a numeric array, calendar duration array, or logical array. If X is a numeric array, it must contain only integer values. That is, you cannot create fractional calendar units.

Extended Capabilities

Introduced in R2014b