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!
    5 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
We want to know how often a day repeats.
0 Commenti
Risposte (2)
  Isabella Osetinsky-Tzidaki
      
 il 12 Dic 2016
        
      Modificato: Isabella Osetinsky-Tzidaki
      
 il 12 Dic 2016
  
      % A is N by 3 matrix (y,M,d)
B=datetime(A,'Format','yyyyMMdd');
C=char(B);
D=str2num(C);
F=unique(D);
L=length(F);
Answer=nan(L,2); % pre-allocate date and its occurrence columns
for i=1:L
    n=length(find(D==F(i)));
    Answer(i,:)=[F(i) n];
end
0 Commenti
  Star Strider
      
      
 il 12 Dic 2016
        Another approach:
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]
Result =
        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.
0 Commenti
Vedere anche
Categorie
				Scopri di più su Dates and Time in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!