Borrar filtros
Borrar filtros

Average values per hour per day from a timeseries

2 visualizaciones (últimos 30 días)
Hammad Khan
Hammad Khan el 19 de Feb. de 2020
Respondida: Mihir el 18 de Jun. de 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.

Respuestas (1)

Mihir
Mihir el 18 de Jun. de 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.

Categorías

Más información sobre Time Series Events en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by