MATLAB: Vector of dates going back one rolling year

date listrolling year

I need to generate a rolling 1 year list of dates. I've tried using:
A=datevec(now);
DList=datenum(A(1), A(2):-1:A(2)-12, eomday(A(1), A(2)));
which will make the list I want as long as the current month is December, however it currently is not. So I get a list that goes back from November 2015 and then has multiple entries for Jan 2015 as it doesn't roll back to 2014.
Is there a straight forward way to get what I need? I don't have access to the financial toolbox so any of the functions included in it are out for me.
Thanks, Ben

Best Answer

You can subtract one from the year field:
>> Vend = clock;
>> Nend = datenum(Vend);
>> Nbeg = datenum([Vend(1)-1,Vend(2:end)]);
>> Nall = Nbeg:Nend;
>> Vall = datevec(Nall);
You might also want to adjust Nbeg by one, depending on whether you want to include start on the same date as the period ends on.
EDIT this code gives just first of each month, over the past twelve months (regardless of the end month):
>> Vend = clock;
>> Nbeg = datenum([Vend(1)-1,1+Vend(2),1]);
>> Vbeg = datevec(Nbeg);
>> Nall = datenum(Vbeg(1),Vbeg(2)+(11:-1:0),1);
>> datestr(Nall)
ans =
01-Nov-2015
01-Oct-2015
01-Sep-2015
01-Aug-2015
01-Jul-2015
01-Jun-2015
01-May-2015
01-Apr-2015
01-Mar-2015
01-Feb-2015
01-Jan-2015
01-Dec-2014