www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ConvertDurationsToArrayOfYearsExample.m

    %% Convert Durations to Numeric Array of Years
%%
% Find the difference between two arrays of dates. The output is a |duration| array.

% Copyright 2015 The MathWorks, Inc.

t1 = datetime(2007:2010,10,1);
t2 = datetime(2014,05,1);
dt = t2 - t1
%%
% Convert each duration in |dt| to a number of fixed-length years.
Y = years(dt)