MATLAB: Trouble converting timestamp using date and date_vectors

datedatetime

1) I have 6 variables, ref_year,mth,day,hr,min,sec that corresponds to a reference time. I am having trouble getting MATLAB to recognise it as a date vector when I put them into a single 1×6 matrix. How could I convert them into a datenum?
I understand DateVector function https://www.mathworks.com/help/matlab/ref/datenum.html#inputarg_DateVector accounts for it:
If an element falls outside the conventional range, datenum adjusts both that date vector element and the previous element. For example, if the minutes element is 70, datenum adjusts the hours element by 1 and sets the minutes element to 10. If the minutes element is -15, then datevec decreases the hours element by 1 and sets the minutes element to 45. Month values are an exception. datenum sets month values less than 1 to 1.

Best Answer

base_ts = datenum([double([ref_year, ref_mth, ref_day, ref_hr, ref_min]), double(ref_sec)]);
timestamp = base_ts + secs_after_datenum / (24*60*60);