Using timetable to sort and apply functions to data with a timestep greater than one year
3 views (last 30 days)
Show older comments
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 Comment
Accepted Answer
Ameer Hamza
on 2 Dec 2020
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 Comments
Steven Lord
on 2 Dec 2020
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)
More Answers (0)
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!