MATLAB: Finding the end date of each month in the own sequence of dates

dates eomday eomdateMATLAB

Dear all,
I have the following sequence of dates ("mm/dd/yy" format).
dates = ['01/01/97'
'01/23/97'
'01/27/97'
'01/31/97'
'02/06/97'
'02/07/97'
'02/10/97'
'02/21/97'
'02/24/97'
'02/27/97'
'03/11/97'
'03/27/97'
'03/28/97'];
I would like to find the end date for each month ('01/31/97','02/27/97','03/28/97'). Please note, that the end date of each month does not correspond to the calender end date of each month. So, simply using the "eomday" or "eomdate" function won't work.
Thanks a lot!

Best Answer

dat=datevec(dates)
[~,idx]=unique(dat(:,1:2),'rows','last')
res=dates(idx)