How to separate and order timetable data by year
4 次查看(过去 30 天)
显示 更早的评论
data = readtable('USA_SITE_004_final.txt'); %import text file and present as table
data_nan = standardizeMissing(data, -999); %return '-999' values as 'NaN'
hourly_temp_rain_sm = data_nan(:, [1 5 11 26]); %extract key variables
TT = table2timetable(hourly_temp_rain_sm); %form timetable
daily_temp_rain_sm = retime(TT, 'daily', 'mean'); %retime data to obtain daily averages
daily_sm = daily_temp_rain_sm(:,3);
Hi, i have created a timetable and retimed soil moisture data here to obtain daily averages for a period of several years. I now want to be able to obtain a metric for each year and to do this i will need to separate the data into years, keeping the daily averages each year. I hope that makes sense and thank you in advance for any help.
0 个评论
回答(1 个)
Adam Danz
2021-11-15
编辑:Adam Danz
2021-11-15
> I now want to be able to obtain a metric for each year and to do this i will need to separate the data into years, keeping the daily averages each year.
You can use retime with yearly intervals. By storing this in a different variable, you can also keep the daily values.
dt = datetime(1999,1,1) + days(0:1:2000)';
rainfall = rand(numel(dt),1);
TT = timetable(dt, rainfall) % Daily rainfall
yearlyTT = retime(TT,'yearly','mean') % yearly avg
Note that the aggregate method can be a function handle if your metric is not a built-in option. See doc retime for more info.
6 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Timetables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!