Time Stamp Series Function
2 views (last 30 days)
Show older comments
I'm trying to find/create a function that takes input of startDate, endDate, and units. The output should be a series of time elements in regular (or irregular in the case of months as units) bins separated by units.
Parameters that allow specification of start dates or day of week starts in the case units='weeks' will be necessary.
example: >> output=makeTimeSeries([2010,1,1,0,0,0],[2010,3,1,0,0,0],'months')
result: [2010,1,1,0,0,0], [2010,2,1,0,0,0], [2010,3,1,0,0,0]
So far I'm just writing a giant switch statement.
Anyone have familiarity with this problem? Is there a nice function out there or a library available?
0 Comments
Answers (1)
Walter Roberson
on 24 Jan 2011
Use ismember or similar to look up the unit name in a table. The index would tell you which index offset in the datevec had to be incremented. week would probably have to be special cased for the index and increment value. Anyhow, add the increment at the appropriate index into the datevec, convert the resulting datevec to a serial date, compare the serial date to the serial date for the end-point; if it exceeds the end you've gone further than you need so break. If not, convert the serial date back to a datevec: that datevec will have any adjustments necessary due to wrapping minutes or hours or months or years, so append that datevec to the end of your output.
0 Comments
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!