MATLAB: Problem when using retime

MATLABretime

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?

Best Answer

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