Average values per hour per day from a timeseries

2 vues (au cours des 30 derniers jours)
Hammad Khan
Hammad Khan le 19 Fév 2020
Réponse apportée : Mihir le 18 Juin 2023
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.

Réponses (1)

Mihir
Mihir le 18 Juin 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.

Catégories

En savoir plus sur Time Series Events dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by