How to separate and order timetable data by year
조회 수: 3 (최근 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에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!