Subset using time range following specific time
1 view (last 30 days)
Show older comments
Louise Wilson on 29 Jun 2021
Commented: Louise Wilson on 1 Jul 2021
I have two tables (see attached screenshot.) Both tables have a list of datetimes. I want to select the value from counts_subset.BoatCount if the counts_subset.DateTime falls within any of dBtable.DateTime+2 minutes, and then I went to append that count to the same row of the matching datetime. I can do it with withtol, but withtol selects 2 minutes before and after, whereas I only want to select two minutes after. Is this possible?
tmatch_tt1=counts_subset(withtol(dBtable.DateTime,tol),:).DateTime; %using withtol
Update: I figured out by subsetting with withol(2 minutes) and then selecting only those datetimes which occur after 2 minutes. It would be good to know if there is a quicker/more efficient way though.
%select the times in table that match countd times with tolerance
%extract rows in table that are within 2 min
%use synchronize to join the matched rows
%find datetimes which occur AFTER 2 mins
%get wav datetime from .wav filename
%get image datetime from img filename
%only select rows where img dt is after wav dt
Seth Furman on 1 Jul 2021
Two alternative workflows are
- Shift the midpoint and tolerance passed into withtol to achieve the desired range.
- Use logical subscripting to only include those datetimes in the desired range.
dt = datetime(2000,1,1)+minutes(0:5:50)'
posNeg = [-1 1];
posNeg = posNeg(randi(2,11,1))';
dtNoisy = dt+minutes(2.5).*rand(11,1).*posNeg;
tt = timetable(dtNoisy,(1:11)')
Shift the midpoint and tolerance passed into withtol to achieve the desired range
Use logical subscripting to only include those datetimes in the desired range
tt(minutes(0) <= tt.dtNoisy-dt & tt.dtNoisy-dt <= minutes(2),:)
More Answers (0)
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!