Average values per hour per day from a timeseries
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Mihir
2023-6-18
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time Series Events 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!