MATLAB: Vector of decimal day

timevector

Is it possible to create a vector of decimal days?
I want to generate a time vector which starts and ends at specific dates and has an interval of 4 minutes between each time (in decimal day). For example: start on the first of jan 2009 and end on the 30th of April 2009 with a time stamp of 4 minutes between each time stamp!

Best Answer

Here is one of many possible ways.
HOURSPERDAY = 24;
MINUTESPERHOUR = 60;
MINUTESPERDAY = HOURSPERDAY * MINUTESPERHOUR;
firstDate = '2009-01-01';
lastDate = '2009-04-01';
firstDatenum = datenum(firstDate,'yyyy-mm-dd');
lastDatenum = datenum(lastDate, 'yyyy-mm-dd');
fourMinuteDatenumVector = (firstDatenum:4/MINUTESPERDAY:lastDatenum)';
fourMinuteTimestampVector = datestr(fourMinuteDatenumVector);
I wasn't quite clear on how you wanted the output. The variable fourMinuteDatenumVector is a MATLAB datenum format. The variable fourMinuteTimestampVector is a timestamp format. You can use the datestr() function to convert to many different formats.