Extract data from a timetable excluding an specific date
3 次查看(过去 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!