SOLVED - Slip a single array in three unequal parts, three years observation with a leap year in between

2 visualizaciones (últimos 30 días)
Hello everybody,
I am very new to matlab and I need all your help:
I have this array 26304 x 1 that are hourly observations of sst over three years: i need to split this array in three arrays corresponding to year 2014, 2015 and 2016. I can't split the array in equal parts since year 2016 is a leap year.
I will then compute the monthly mean for each months in each year and merge the data together again, in order to have a single array 1096x1.
Thank you very much!
  2 comentarios
Cris LaPierre
Cris LaPierre el 22 de Jun. de 2021
Not sure how monthly data for 3 years gives you 1096. Wouldn't 12 months x 3 years = 36 rows of data? Did you mean daily instead of monthly?
CARLOTTA DENTICO
CARLOTTA DENTICO el 23 de Jun. de 2021
Sure, I meant monthly (so at the end I will have 1 x 36) but when I wrote it I made the calculation considering daily data!

Iniciar sesión para comentar.

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 22 de Jun. de 2021
Editada: Cris LaPierre el 23 de Jun. de 2021
I would look into timetables and groupsummary. With a timetable, you can add a date and time to each row, and then with groupsummary, you can group your data by year and month, and compute the mean of each group.
data = rand(26304,1);
dataTT = timetable(data,'TimeStep',hours(1),'StartTime',datetime(2014,1,1))
dataTT = 26304×1 timetable
Time data ____________________ ________ 01-Jan-2014 00:00:00 0.083863 01-Jan-2014 01:00:00 0.72604 01-Jan-2014 02:00:00 0.26453 01-Jan-2014 03:00:00 0.63959 01-Jan-2014 04:00:00 0.46283 01-Jan-2014 05:00:00 0.60372 01-Jan-2014 06:00:00 0.53723 01-Jan-2014 07:00:00 0.5202 01-Jan-2014 08:00:00 0.56378 01-Jan-2014 09:00:00 0.76735 01-Jan-2014 10:00:00 0.97978 01-Jan-2014 11:00:00 0.03396 01-Jan-2014 12:00:00 0.08551 01-Jan-2014 13:00:00 0.15598 01-Jan-2014 14:00:00 0.49928 01-Jan-2014 15:00:00 0.6527
avgT = groupsummary(dataTT,"Time","month","mean")
avgT = 36×3 table
month_Time GroupCount mean_data __________ __________ _________ Jan-2014 744 0.48536 Feb-2014 672 0.49625 Mar-2014 744 0.50871 Apr-2014 720 0.49382 May-2014 744 0.52113 Jun-2014 720 0.50644 Jul-2014 744 0.50069 Aug-2014 744 0.48957 Sep-2014 720 0.48952 Oct-2014 744 0.49456 Nov-2014 720 0.50474 Dec-2014 744 0.50123 Jan-2015 744 0.5092 Feb-2015 672 0.50245 Mar-2015 744 0.49252 Apr-2015 720 0.51885

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by