retime timetable based on custom definition of year
Mostrar comentarios más antiguos
Hi and thanks in advance.
I have a timetable that i want to retime to yearly data and find the counts of variable 'cat'. THe issue is that unlike the usualy definition of 'year' in Matlab 'retime' (which is Jan 1 to Dec 31), I want to define my year as starting on July 1 in the current year and ending on Jun 30 in the next year and use this definition to retime my timetable.
One of the method that i can think of is offsetting my data by adding months(5) to the original time and then retimeing it 'yearly' and manually labeling my graphs x-axis (this can be bit tedious for me). Im hoping that there is a better way around this.
highly appreciate if someone can help.
Respuesta aceptada
Más respuestas (1)
Based on your description I suspect you're calling retime with the second input being 'yearly'. As far as I'm aware there's no option to specify when the 'year' starts for purposes of the newTimeStep input argument's definition of 'yearly'. However, you could call retime with a vector of times (the syntax using the newTimes input argument rather than the newTimeStep input.) It would require you to determine the starting and ending years you need to include in that newTimes vector, but that shouldn't be that difficult.
n = 10;
y = randi([1990, 2030], n, 1);
m = randi(12, n, 1);
d = randi(28, n, 1); % No 29th, 30th, or 31st of any month
randomDatetimes = datetime(y, m, d)
firstDate = min(randomDatetimes)
yearOfFirstDate = year(firstDate)
if firstDate > datetime(yearOfFirstDate, 7, 1)
disp("firstDate occurs on or after July 1st, " + yearOfFirstDate + ...
". Use datetime(" + yearOfFirstDate + ", 7, 1) as your starting date.")
else
disp("firstDate occurs before July 1st, " + yearOfFirstDate + ...
". Use datetime(" + (yearOfFirstDate-1) + ", 7, 1) as your starting date.")
end
sampleVector = firstDate + calyears(0:5)
Categorías
Más información sobre Timetables en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!