MATLAB: Creating index from datetime vector days

ymd indexing

Hi,
I have a 100×1 datetime vector. I have extracted the values of the day using the ymd function: [~,~,d] = ymd(input).
How can I create a vector with a unique identifier for every period from the 15th to the 14th in the days vector, d (each sequence of 15 to the next 14). (i.e. from jan 15 – feb 14, i could have 1's, from feb 15 – mar 14, i can have 2s, etc.)
Any help would be appreciated. Thx in advance!
DB

Best Answer

Take the month number output as well as the day output. If the day is less than 15, subtract 1 from the month number to get the index (if the month number was 1, substitute 12 for previous year); otherwise use the month number directly.