Problem when using retime

9 次查看(过去 30 天)
I have a timetable with temperature data from a meteorological station.
I use following function to pick out the daily maximum values and that works fine.
dailymax = retime(temptt, 'daily', 'max');
My problem is that in the column with the date and time (in the the resulting timetable), the time changes to 0:00 in every row. My date format is yyyy-mm-dd hh:mm.
Is there anyone who knows how to fix this?
  3 个评论
Sofie Petersson
Sofie Petersson 2019-1-31
In my timetable "temptt" there are two columns, one with the date + time and one with the measured temperature at that time. The function picks out the highest value for each day and I want the corresponding time. (The time from the same row).
Sofie Petersson
Sofie Petersson 2019-1-31
Or do I missunderstand the retime-function? Is there any other way to find the daily maximum values and get the correct time?

请先登录,再进行评论。

采纳的回答

Guillaume
Guillaume 2019-1-31
You can't use retime for that. retime is designed to work with timetables that can have more than one variable. In this case, it picks the max of each variable and there's no guarantee the max of each variable is on the same row. And of course, when the aggregration function is something like mean there can't be a matching row.
One way to obtain what you want:
daygroup = discretize(tempTT.Properties.RowTimes, 'day'); %find which group each row belongs to
[~, grouprow] = splitapply(@max, tempTT{:, 2}, daygroup); %find location of max within the group
tablerow = find(diff([0; daygroup])) + grouprow - 1; %add start row of each group to get max location in table
dailymax = tempTT(tablerow, :)
Instead of tempTT.Properties.RowTimes you can use tempTT.NameOfTimeColumn and instead of tempTT{:, 2} you can use tempTT.NameOfVariable

更多回答(1 个)

Peter Perkins
Peter Perkins 2019-1-31
Sofie, if I understand correctly, you want to find, within each day, the maximum temperature, and the date/time at which that maximum occurred. Guillaume is correct that retime can't do that, unless you trick it. But there are easier ways.
As Guillaume says, splitapply is one way. Another is in my response to the same question a couple weeks ago.

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by