Finding 8 day averages for timeseries data

I have two data types; daily runoff and 8-day chlorophyll.
I've created loops to generate monthly and yearly averages for the chlorophyll and runoff, but am not sure how to make 8-day averages for the runoff.
Here is one of my yearly loops
year_counter = 1;
y2 = runoff_loop_dates(:,1);
yearUN = unique(y2);
for ii = 1:length(yearUN)
idx = find(y2==yearUN(ii));
runoff_year(ii) = nanmean(runoff(idx));
year_counter = year_counter + 1;
end
How can I change this to find 8-day averages? Thank you.

 Accepted Answer

Convert your data to a timetable and use retime to compute monthly/yearly/8-day averages (also see array2timetable).
If you have any trouble, share your updated code in a comment and I'd be happy to help straighten things out.

1 Comment

Thank you so much for taking the time to reply - my code is working now. (retime is a much easier method than the one I was using!)

Sign in to comment.

More Answers (0)

Asked:

on 2 Jun 2021

Commented:

on 3 Jun 2021

Community Treasure Hunt

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

Start Hunting!