MATLAB: How to have datetime for specific range

datetimeMATLABtime

Hi,
I want to have a datetime, monthly from 1982 to 2015, like this:
1/1/1982
2/1/1982
3/1/1982
12/31/2015
how to have it?

Best Answer

Try this:
dt1 = datetime([1982 01 01]);
dt2 = datetime([2015 12 31]);
dt_vec = dt1 : calmonths(1) : dt2;
FirstFive = dt_vec(1:5) % Display Results (Delete Later)
producing:
FirstFive =
1×5 datetime array
01-Jan-1982 01-Feb-1982 01-Mar-1982 01-Apr-1982 01-May-1982