Synchronize timetables with tolerance of 5 minutes
5 次查看(过去 30 天)
显示 更早的评论
I have two tables with common information and I would like to synchronize them, creating an additional column for data from one column of the second table, using a tolerance of 5 minutes. The two tables do not have exactly the same times in the common DateTime variable, but I would like to add those which match within 5 minutes to the same row.
To detections_t, I would like to add a second column 'BoatCount' from the second table. Since the times don't match exactly I am keen to match within 5 minutes. For example, row 12 of detections_t would have the value of row 2 from boat_counts.
I was thinking I could copy the datetimes in detections_t, move them to nearest ten minute interval, and then match the values in boat_counts that way, but I can't figure out how to change the times in this way. Rather than changing them, I would prefer to create a second datetime variable with the adjusted times.
%read data
detections_t=readtable('H:\SoundTrap\Boats\Manual Vessel Detections\boatPresenceAbsence_table.csv');
boat_counts=readtable('H:\Cameras\Virtual Machine\Processed Images\Boat Counts\boatcounts_final_10mins_concat.csv');
%To detections_t, we want to add the boat count for the closest time to
%each row. This will restrict the data to 8-5pm.
tol=seconds(300);
detections_t=table2timetable(detections_t); %convert to tt
%select the times in boat_counts that match detections times with tolerance
tmatch_tt1=detections_t(withtol(boat_counts.DateTime,tol),:).DateTime;
Error using withtol (line 78)
Tolerance exceeds half the smallest interval between subscript times, and might result in
selecting duplicate rows. Tolerance must be less than 30 sec.
3 个评论
Mathieu NOE
2020-12-11
yes, you should probably first round the two time tables (to the nearest 10 min) and then synchronize
% round time to nearest 10 min
tt = datetime('now','Format','yyyy-MM-dd HH:mm')
tt.Minute = 10 * floor(tt.Minute/10);
tt.Second = 0;
tt
回答(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!