MATLAB: Remove leading zeros from dates strings

datestrdatetime

Hello
I need to find the number of times a set of dates is included in a large text file. The problem is that the text file does not use leading zeros for months and days.
My code should look something like this:
myText=fileread('largeFile.txt');
dayOne=datetime('06/05/20','InputFormat','MM/dd/yy')
for it=1:10
numberOfTimes(it)=size(regexp(myText, datestr(dayOne+days(it), 'mm/dd/yy')), 2);
end
Thanks

Best Answer

You can use histogram() to count occurences, either with datetime or categoricals as input.
dates = datetime(2010,1,12) + rand(1000,1)*days(365);
% with categoricals
dates_cell = cellstr(datestr(dates,'mm/dd/yy'));
dates_cat = categorical(dates_cell);
H = histogram(dates_cat)