We have a matrix containing the year month and day of data points. We want to find out how often each day occurs. Thanks in advance!
3 views (last 30 days)
Isabella Osetinsky-Tzidaki on 12 Dec 2016
Edited: Isabella Osetinsky-Tzidaki on 12 Dec 2016
% A is N by 3 matrix (y,M,d)
Answer=nan(L,2); % pre-allocate date and its occurrence columns
Star Strider on 12 Dec 2016
M = [2016 12 12; 2016 12 11; 2016 12 11; 2016 12 10]; % Create Data
dn = datenum( M ); % Compute Date Numbers
[Ud,ia,ic] = unique(dn, 'stable'); % The 'stable' Argument Retains The Original Order
date_tally = accumarray(ic, 1); % Count Occurrences
Result = [M(ia,:), date_tally]
2016 12 12 1
2016 12 11 2
2016 12 10 1
You will need to make appropriate changes for the format of your dates (you did not specify what they were). This should do what you want.