Problem when using retime
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Sofie Petersson
il 31 Gen 2019
Commentato: Sofie Petersson
il 1 Feb 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 Commenti
Risposta accettata
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
Più risposte (1)
Peter Perkins
il 31 Gen 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.
0 Commenti
Vedere anche
Categorie
Scopri di più su Tables in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!