Borrar filtros
Borrar filtros

How can I split up hourly data into seasons?

11 visualizaciones (últimos 30 días)
greg
greg el 8 de Mayo de 2019
Comentada: Razvan Carbunescu el 9 de Mayo de 2019
I'm looking at a data set that covers ~40 years and I want to study seasonal variations. I'm thinking I should be able to assign the first point an exact date and then knowing each value is at 1 hour increments Matlab can assign dates to the whole dataset. From here I would want to group together months into seasons and run my function on each season seperately. I've been trying to use timetable and datetime in matlab to do this and I can't figure out how to assign the date to the start of my time series. Any ideas on the best way to go about this?
  1 comentario
Adam Danz
Adam Danz el 8 de Mayo de 2019
"I'm thinking I should be able to assign the first point an exact date and then knowing each value is at 1 hour increments Matlab can assign dates to the whole dataset."
This method is susceptible to continually growing error. If you miss an hourly sample even once per year, by the time you're at the end of your 40-year dataset the time will be off by more than a day and a half.
Does your data not contain time stamps or any time references at all?

Iniciar sesión para comentar.

Respuestas (1)

Adam Danz
Adam Danz el 8 de Mayo de 2019
Editada: Adam Danz el 9 de Mayo de 2019
The code below creates a vector of date-time starting at "t1", ending at "t2" at intervals of "interval" as you decribed as a potential solution in your question. Be sure to heed the warning in my comment under your question if you use this method.
t1 = datetime(1979,03,16,14,0,0); %start date/time
t2 = datetime(2019,03,16,0,0,0); %end date/time
interval = hours(1); %sample interval
timeSamples = (t1 : interval : t2).';
View the time stamps
timeSamples(1:5) %first 5
ans =
5×1 datetime array
16-Mar-1979 14:00:00
16-Mar-1979 15:00:00
16-Mar-1979 16:00:00
16-Mar-1979 17:00:00
16-Mar-1979 18:00:00
To separate the data into seasons (simplified by groups of months), you can create 4 different logical vectors that identify whether each row of your data is a member of a particular season.
mo = month(timeSamples); %get month numbers
isSummer = ismember(mo, [6,7,8]); %here you define the seasons by month
isAutumn = ismember(mo, [9,10,11]);
isWinter = ismember(mo, [12,1,2]);
isSpring = ismember(mo, [3,4,5]);
Example:
mydata(isWinter,:) % All of your winter data
sum(isWinter) % This tells you how many samples you have from winter
  1 comentario
Razvan Carbunescu
Razvan Carbunescu el 9 de Mayo de 2019
To add on to Adams Solution you can then proceed to use the grouping functions groupsummary, grouptransform to manipulate your data while splitting it into binned parts using the time binning options. See section under groupsummary doc for more details:

Iniciar sesión para comentar.

Categorías

Más información sobre Calendar en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by