This 2-step process is done in 1 line.
- Round the year of the datetime vector to the decade (1999 becomes 1990s)
- Use [G,ID] = findgroups(A) to group the datetime vector by decades.
% Create demo data
dt = (datetime(1981,12,01) : hours(4) : datetime('now'))';
% Assign groups to datetime vector; group by decade
[decadeGroup, decade] = findgroups(floor(year(dt)/10)*10);
decade is a list of decades in your datetime vector.
decadeGroup are positive integers 1:n for n-decades of data.
For example to isolate the 1990s,
NinteenNinties = dt(decadeGroup==find(decade==1990));

