Clear Filters
Clear Filters

Average values per hour per day from a timeseries

2 views (last 30 days)
My table consists of 3 rows. One date, time (hour) and then precipitation value. I want to average the precipitation value for each hour for 365 days. I want to create a new table where I have the averaged precipitation values for each hour of 365 days of year averaged from 10 years. I have used ‘find’ to index the cell location of each value but is there any way I can use this in a loop wthout having to manually write the code for each value 24*365 times? Help would be very appreciated.

Answers (1)

Mihir
Mihir on 18 Jun 2023
Yes, you can use a loop to calculate the hourly averages for 365 days using the find function. Here's an example code that should work:
for day = 1:365
% calculate the indices of the precipitation values for the current day
for hour = 1:24
% calculate the indices of the precipitation values for the current hour of the day
% calculate the hourly average
end
end
You can use nested loops so that you need not write code manually for 24*365 times. We can use a loop to iterate through all 365 days of the year. For each day, we use the find function to calculate the indices of the precipitation values for this day, and then another loop to iterate through all 24 hours of the day. For each hour, we again use the find function to calculate the indices of the precipitation values for this hour, and then calculate the hourly average using the mean function.

Products

Community Treasure Hunt

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

Start Hunting!