vector of decimal day

4 views (last 30 days)
Richard
Richard on 16 Jan 2012
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!

Accepted Answer

the cyclist
the cyclist on 16 Jan 2012
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.

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!