MATLAB: Finding the end date of each month/year

dates

Dear all,
I have the following sequence of dates
dates =[ '23/11/08'
'28/12/08'
'25/01/09'
'22/02/09'
'29/03/09'
'26/04/09'
'24/05/09'
'28/06/09'
'26/07/09'];
Is there any way to find the end date for each of these months.
For example the last date of November 2008 (11/08) is 30/11/08. Similarly, the last date of December 2008 is 31/12/08 and so forth. I have a large vector of “dates” and an “quick” way to find these dates would be better
Thank you

Best Answer

one way
dates =[ '23/11/08'
'28/12/08'
'25/01/09'
'22/02/09'
'29/03/09'
'26/04/09'
'24/05/09'
'28/06/09'
'26/07/09'];
dv = datevec(dates,'dd/mm/yy');
dc = num2cell(dv(:,1:2),1);
enddates = datestr(datenum(dc{:},eomday(dc{:})),'dd/mm/yy');
or
[Y, M] = datevec(dates,'dd/mm/yy');
out = datestr(datenum([Y, M, eomday(Y, M)]),'dd/mm/yy');
second way with use function eomdate from Financial Toolbox
enddates = datestr(eomdate(datenum(dates,'dd/mm/yy')),'dd/mm/yy');
other way
[Y, M] = datevec(dates,'dd/mm/yy');
enddates = datestr(datenum(Y,M+1,1)-1,'dd/mm/yy');