Extract data from a timetable excluding an specific date

6 ビュー (過去 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 Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by