필터 지우기
필터 지우기

Remove rows with less than certain amount of measurements from timetable

조회 수: 8 (최근 30일)
gd
gd 2020년 4월 29일
댓글: Hank 2020년 5월 4일
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
Hank
Hank 2020년 4월 29일
편집: Hank 2020년 4월 29일
If you're willing to share the data, could you attach a .mat file with the time table?
gd
gd 2020년 4월 29일
Hi Henry,
Please see attached .mat

댓글을 달려면 로그인하십시오.

채택된 답변

Hank
Hank 2020년 4월 29일
편집: Hank 2020년 4월 29일
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
gd
gd 2020년 5월 4일
Henry,
Thank you so much for the help. I appreciate you putting in the time to help me. This looks great, thank you again and be well!
Hank
Hank 2020년 5월 4일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by