- 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.
creating a sub date time array
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
ismail bhamjee
am 16 Dez. 2019
Bearbeitet: Adam Danz
am 18 Dez. 2019
I have a datetime array conisisting of dates from the 1980s till recent. it is stored in a date time array. how do i sperate the datetime array into years. for example i want a seperate array for 1980 till 1990 so on and so forth.

my data looks like this.
0 Kommentare
Akzeptierte Antwort
Adam Danz
am 17 Dez. 2019
Bearbeitet: Adam Danz
am 18 Dez. 2019
This 2-step process is done in 1 line.
% 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));
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!