Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

calyears

Calendar duration in years

Syntax

Y = calyears(X)

Description

example

Y = calyears(X) returns an array representing calendar years equivalent to the values in X. Calendar years account for leap days when used in calendar calculations.

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

  • If X is a calendarDuration array, then calyears returns the number of whole years equivalent to each calendar duration in X.

Examples

collapse all

X = magic(4);
Y = calyears(X)
Y = 4x4 calendarDuration array
   16y    2y    3y   13y
    5y   11y   10y    8y
    9y    7y    6y   12y
    4y   14y   15y    1y

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

X = calmonths(21:25) + caldays(8)
X = 1x5 calendarDuration array
    1y 9mo 8d   1y 10mo 8d   1y 11mo 8d        2y 8d    2y 1mo 8d

Y = calyears(X)
Y = 

     1     1     1     2     2

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.

Output Arguments

collapse all

Calendar years, returned as a scalar, vector, matrix, or multidimensional array. Y is the same size as X. The data type of Y depends on X.

  • If X is a numeric array, then Y is an array of calendar durations in units of equivalent flexible-length calendar years.

  • If X is a calendarDuration array, then Y is a double array of integer values representing whole calendar years.

Tips

  • calyears creates years that account for leap days when used in calendar calculations. To create exact fixed-length (365.2425 day) years, use the years function.

Extended Capabilities

Introduced in R2014b

Was this topic helpful?