Extract data from a timetable excluding an specific date
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello!
I have two timetables. In the first one (tt_1) I have dates and a variable (v1). From this timetable I want to extract the dates where the variable is less than 12.5.
Then I want to filter my second timetable (tt) from these dates. This means, I want to create a new timetable (tt_2) with only the information from tt excluding the dates selected tt_1.
An example would be to get to table tt_2 from tt_1 and tt.
tt_1 = timetable(datetime({'13/04/2018';'25/04/2018';'28/04/2018'}), [12;12.5;10]);
tt = timetable(datetime({'13/04/2018';'25/04/2018';'26/04/2018';'28/04/2018'}), [37.3;39.1;42.3;21]);
tt_2 = timetable(datetime({'25/04/2018';'26/04/2018'}), [39.1;42.3]);
Any ideas? I would be very grateful.
Thanks
댓글 수: 0
채택된 답변
J. Alex Lee
2021년 2월 20일
This should work. Most of these steps should be straightforward..."ismember" may have been the key
tt_1 = timetable(datetime({'13/04/2018';'25/04/2018';'28/04/2018'}), [12;12.5;10]);
tt = timetable(datetime({'13/04/2018';'25/04/2018';'26/04/2018';'28/04/2018'}), [37.3;39.1;42.3;21]);
tt_2_ref = timetable(datetime({'25/04/2018';'26/04/2018'}), [39.1;42.3]);
% find rows in tt_1 satisfying criterion on variable
vflt = tt_1.Var1 < 12.5
% find corresponding dates in tt_1
texcl = tt_1.Time(vflt)
% find rows where times in tt are not in texcl
tflt = ~ismember(tt.Time,texcl)
% extract filtered rows from tt
tt_2 = tt(tflt,:)
% check against ref
isequal(tt_2,tt_2_ref)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Timetables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!