MATLAB: How to turn monthly data to annual data? data attached for example

beginnerMATLAB

On the file I have attached, how would I turn those months into years using an average? So for example every month of 1959 into just one piece of data where every month is averaged out together. Secondly, what do I do with the start and the end since there's not 12 months for 1958 or 2020?
Thank you,
Richard Marx

Best Answer

Use the retime function to change your time step to 'yearly'. For method, use 'mean'.
load EXAMPLEQUESTIONDATA.mat
retime(TB6MS_,'yearly','mean')
ans = 63x1 timetable
Time Var1 ___________ ______ 01-Jan-1958 3.01 01-Jan-1959 3.815 01-Jan-1960 3.2117 01-Jan-1961 2.5917 01-Jan-1962 2.8992 01-Jan-1963 3.2583 01-Jan-1964 3.6817 01-Jan-1965 4.0533 01-Jan-1966 5.0608 01-Jan-1967 4.6208 01-Jan-1968 5.4717 01-Jan-1969 6.8608 01-Jan-1970 6.5083 01-Jan-1971 4.5117 01-Jan-1972 4.4842 01-Jan-1973 7.1992
What to do with the data from years that do not have 12 months of data depends on what is accepted practice in your field. There is no hard and fast rule. I'd just be careful to not misrepresent your data. For me, you only have a value for Dec 1958, so I'd probably drop it. However, for 2020 you have Jan-Nov, so I'd probably keep it.