Extract data from a timetable excluding an specific date

조회 수: 3 (최근 30일)
Angelavtc
Angelavtc 2021년 2월 20일
답변: J. Alex Lee 2021년 2월 20일
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

채택된 답변

J. Alex Lee
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개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by