Using timetable to sort and apply functions to data with a timestep greater than one year
1 回表示 (過去 30 日間)
古いコメントを表示
I am working with daily temperature data; min, max, and mean over a period of 40 years. I have no problem using the timetable functionality to sort the data, by year, month,etc, however I want to compare the data for the lifetime and find the standard deviation and median. I know this is possible to do using arrays and for loops to sort and group the data, but because I have it set-up with timetables already I think it would be more elegant? Using the retime function I could change the timestep, but getting the appropriate data from that didn't work.
Thanks!
1 件のコメント
採用された回答
Ameer Hamza
2020 年 12 月 2 日
If you mean that instead of regular time steps, e.g., monthly, yearly, etc. You want to use a custom time-step, you can use the following signature of retime() function
TT2 = retime(TT1,'regular',method,'TimeStep',dt)
here dt can be defined using duration().
9 件のコメント
Steven Lord
2020 年 12 月 2 日
dt = datetime(2000,1,1):datetime(2010,12,31);
data = rand(size(dt));
TT = timetable(dt.', data.', 'VariableNames', {'data'});
I'd use groupsummary for this. To get the mean of the data for each month and year combination in the timetable's Time:
resultPerMonthAndYear = groupsummary(TT, 'Time', 'month', @mean)
To get the mean of the data for each month across all the years in the data set:
resultPerMonth = groupsummary(TT, 'Time', 'monthofyear', @mean)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!