check consecutive dates matlab

250 views Asked by At

I have a cell array containing dates:

unique_days{1,1} =     '15/03/2012';
unique_days{2,1} =     '16/03/2012';
unique_days{3,1} =     '17/03/2012';
unique_days{4,1} =     '19/03/2012';
unique_days{5,1} =     '20/03/2012';

I would like to check if the cell array contains consecutive days. In particular I would like to create a vector consecutive_days that contains 1 if unique_days{i+1,1} is the day after unique_day{i,1}

In this case consectutive_days shoud be = [1 1 0 1]

Could you help me?

1

There are 1 answers

0
Luis Mendo On BEST ANSWER

Use datenum and then diff:

consecutive_days = diff(datenum(unique_days, 'dd/mm/yyyy')).'==1;