Remove rows with less than certain amount of measurements from timetable
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi all,
I have a 517x2 timetable that I've reduced based on some conditions shown in my code below. Next, I want to remove any rows with measurements that do not contribute a full day's worth of measurements. A full day contains 8 measurements, so in the photo we see that rows with April 19 and May 6 dates would be removed, but May 7 and 8 would not since they contain 8 measurements per day each. Please let me know if this does not make sense. Any tips are appreciated, this is my first time using timetables / tables. Thank you very much in advance.
%% Hm0 <4m & Tp > 8s
Hm0_OM = Hm0_yy';
Tp_OM = Tp_yy';
dnum_OM = dnum_yy';
% Create table with values
OM_occ = timetable(dnum_OM, Hm0_OM, Tp_OM);
%Remove values based on O&M requirements
OM_occ(OM_occ.Hm0_OM > 1.5,:)=[];
OM_occ(OM_occ.Tp_OM > 8,:)=[];
% Remove rows that do not contribute to a full day's worth of measurements (8 per day)
2 comentarios
Respuesta aceptada
Hank
el 29 de Abr. de 2020
Editada: Hank
el 29 de Abr. de 2020
I have some idea about getting the times and unique times
T = tab.Time
uT = unique(T);
and then checking how many times each unique time appears in T in a for loop. Let me know if it needs tweaking.
rm = zeros(size(T),'logical'); % array tracking rows to be removed
for i=1:length(uT)
A = uT(i)==T; % logical array, size of T
if sum(A)<8 % sum(A) counts the entries with that unique datetime
rm = rm | A; % add the rows to the rm array by logical or.
end
end
T(rm,:) = []; % delete rows that didn't match spec
If we start removing rows within the loop, the loop index will lose sync with the array, hence the rm array.
5 comentarios
Hank
el 4 de Mayo de 2020
The trick was finding a way to compare the datetime objects that would be true if they're the same date (ignoring the time of day). I think converting to strings was a sloppy way to do this, but it allows us to use the unique function and to count dates that are the same with strcmp.
I'd love to see if someone comes up with a cleaner method.
Más respuestas (0)
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!