Extract data from a timetable excluding an specific date

7 次查看(过去 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

采纳的回答

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