date - matlab - only keep days where 24 values exist -


say have dataset:

jday = datenum('2009-01-01 00:00','yyyy-mm-dd hh:mm'):1/24:...     datenum('2009-01-05 23:00','yyyy-mm-dd hh:mm'); datev = datevec(jday); datev(4,:) = []; datev(15,:) = []; datev(95,:) = [];  dat = rand(length(jday),1) 

how possible remove of days have less 24 measurements. example, in first day there 23 measurements need remove entire day, how repeat of array?

a quick solution group year, month, day unique(), count observation per day accumarray() , exclude less 24 obs 2 steps of logical indexing:

% count observations per day [undate,~,subs] = unique(datev(:,1:3),'rows'); counts = [undate accumarray(subs,1)] counts =         2009           1           1          22         2009           1           2          24         2009           1           3          24         2009           1           4          24         2009           1           5          23 

then, apply criteria counts , retrieve logical index

% index meet criteria idxc = counts(:,end) == 24 idxc =       0       1       1       1       0  % keep meet criteria (optional, visual inspection) counts(idxc,:) ans =         2009           1           2          24         2009           1           3          24         2009           1           4          24 

finally, find members of dat fall selected counts second round of logical indexinf through ismember():

idxdat = ismember(subs,find(idxc)) dat(idxdat,:) 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -