Problem when using retime

9 vues (au cours des 30 derniers jours)
Sofie Petersson
Sofie Petersson le 31 Jan 2019
Commenté : Sofie Petersson le 1 Fév 2019
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 commentaires
Sofie Petersson
Sofie Petersson le 31 Jan 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 le 31 Jan 2019
Or do I missunderstand the retime-function? Is there any other way to find the daily maximum values and get the correct time?

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 31 Jan 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 commentaire
Sofie Petersson
Sofie Petersson le 1 Fév 2019
Thanks a lot! This was exactly what I wanted to do!

Connectez-vous pour commenter.

Plus de réponses (1)

Peter Perkins
Peter Perkins le 31 Jan 2019
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.

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by