Function to use withtol but only forward in time?

1 view (last 30 days)
I have a timetable where the rows are datetimes. I then have a second timetable and I want to match the values in the second timetable to the first, but only where the times match within a certain time range. I want to include only those rows from the second timetable which occur within 2 minutes of the datetimes in the first. I can do this using withtol, but then I get + and - 2 minutes. How do I set the tolerance to only include 2 minutes after?
tol=minutes(2);
%we get a value for boat counts if photo was captured 2 minutes either side
%of hydrophone recording
for a=1:length(sites)
dBtable=dBcalcs.(sites{a});
counts_subset_rows=contains(boat_counts.Site(:),sites{a});
counts_subset=boat_counts(counts_subset_rows,:);
%select the times in boat_counts that match detections times with tolerance
tmatch_tt1=counts_subset(withtol(dBtable.DateTime,tol),:).DateTime;
%extract rows in boat_counts that are within 2 min of hydrophone recordings
[Lia,Loc]=ismember(tmatch_tt1,counts_subset.DateTime)
counts_subset_new=counts_subset(Loc,:);
%change detections datetimes to closest datetime of images
%(specific datetime of hydrophone recording remains in spectrogram filename
%of each row)
dBtable=table2timetable(dBtable);
tt2_matched=retime(dBtable,tmatch_tt1,'nearest');
%use synchronize to join the matched rows
new_table=synchronize(tt2_matched,counts_subset_new);
new_table.DateTime=datetime(new_table.DateNum,'ConvertFrom','datenum');
dBcalcs_CameraCounts.(sites{a})=new_table;
end

Answers (0)

Categories

Find more on Timetables in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!