MATLAB: Expanding timetable to specific timespan (1year, fill rest with zeros)

datetimeMATLAB and Simulink Student Suiteretimetabletimespantimetable

Hello everybody,
I have some irreuglar spaced measurements of water discharge and battery voltage. I managed to convert the values into a regular spaced timetable with hourly entries, filled with zeroes where no values exist like this:
y20_z1h =
508×3 timetable
dt Nr Qty VBatt
___________________ ___ ___ _____
2020-09-25 10:00:00 1 0 3.21
2020-09-25 11:00:00 0 0 0
2020-09-25 12:00:00 2 1 3.49
2020-09-25 13:00:00 0 0 0
2020-09-25 14:00:00 0 0 0
2020-09-25 15:00:00 0 0 0
2020-09-25 16:00:00 0 0 0
2020-09-25 17:00:00 0 0 0
2020-09-25 18:00:00 0 0 0
2020-09-25 19:00:00 3 1 3.5
2020-09-25 20:00:00 0 0 0
Now I'd like to scale the timetable to exactly one year from '2020-01-01 00:00:00' to '2020-12-31 23:00:00' and also fill the missing values with zeros.
I already tried retime() with
oneyear = retime(y20_z1,'hourly','fillwithconstant', 'Constant',0);
where oneyear is an hourly timetable filled with zeroes like in: https://de.mathworks.com/help/matlab/ref/timetable.retime.html#d122e1135381 but neither this, nor applications with timerange() did the job.
Do you have any idea how to solve this?
Thanks so much in advance!

Best Answer

I was obviously not aware of all the options, retime() offers, so here is the solution:
oneyear = retime(y20_z1,yearvalues,'fillwithconstant', 'Constant',0);
where yearvalues is a vector with all valuesof the year, e.g. created like this:
yearvalues = (datetime(2020,01,01,00,00,00):hours(1):datetime(2020,12,31,23,00,00))';