MATLAB: How to count all occurances of each date in a DateTime Array

datetimefrequency

I have an array of dates formatted in DateTime, spanning over ~2 years. Is there any way for me to tally the number of occurances each date has? I have truncated the values to only have the date portion and the datetime is formatted DD-MMM-YYYY.

Best Answer

I would look into groupsummary. Like Adam suggests, you'll need to remove the time portion for it to work as you intend.
% Simple example
% create an array of overlapping dates
d = datetime('now');
dur = days(randi(10,[50 1])); % random, so results will vary
d = d+dur;
% remove time
t2 = dateshift(d,'start','day')
% Get groupcounts from table
c = groupsummary(table(t2),1)
c =
t2 GroupCount
___________ __________
15-Sep-2020 3
16-Sep-2020 6
17-Sep-2020 8
18-Sep-2020 5
19-Sep-2020 4
20-Sep-2020 4
21-Sep-2020 7
22-Sep-2020 9
23-Sep-2020 1
24-Sep-2020 3