Duration in years
Y = years( returns
an array of years equivalent to the values in
Xis a numeric array, then
durationarray in units of fixed-length years. A fixed-length year is equal to 365.2425 days.
doublearray with each element equal to the number of fixed-length years in the corresponding element of
years function converts between
To display a duration in units of years, set its
Leap years have one extra day. To create an array of calendar years that
account for leap years when used in calendar calculations, use the
Create Duration Array of Fixed-Length Years
X = [1 3 5; 10 12 15]
X = 2×3 1 3 5 10 12 15
Y = years(X)
Y = 2x3 duration 1 yr 3 yrs 5 yrs 10 yrs 12 yrs 15 yrs
Convert Durations to Numeric Array of Years
Find the difference between two arrays of dates. The output is a
t1 = datetime(2007:2010,10,1); t2 = datetime(2014,05,1); dt = t2 - t1
dt = 1x4 duration 57696:00:00 48912:00:00 40152:00:00 31392:00:00
Convert each duration in
dt to a number of fixed-length years.
Y = years(dt)
Y = 1×4 6.5819 5.5799 4.5805 3.5812
X — Input array
numeric array | duration array | logical array
Input array, specified as a numeric array, duration array, or logical array.
Calculate with arrays that have more rows than fit in memory.
This function fully supports tall arrays. For more information, see Tall Arrays.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
This function fully supports code generation. For more information, see Code Generation for Duration Arrays (MATLAB Coder).
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Introduced in R2014b