Problem when using retime

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 Commenti

Guillaume
Guillaume il 31 Gen 2019
Modificato: Guillaume il 31 Gen 2019
What time would you like it to show for each day then?
Sofie Petersson
Sofie Petersson il 31 Gen 2019
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 il 31 Gen 2019
Or do I missunderstand the retime-function? Is there any other way to find the daily maximum values and get the correct time?

Accedi per commentare.

 Risposta accettata

Guillaume
Guillaume il 31 Gen 2019
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 Commento

Thanks a lot! This was exactly what I wanted to do!

Accedi per commentare.

Più risposte (1)

Peter Perkins
Peter Perkins il 31 Gen 2019

0 voti

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.

Community Treasure Hunt

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

Start Hunting!

Translated by