MATLAB Answers

Synchronize timetables with tolerance of 5 minutes

조회 수: 70(최근 30일)
Louise Wilson
Louise Wilson 10 Dec 2020
댓글: Mathieu NOE 11 Dec 2020
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.
detections_t=table2timetable(detections_t); %convert to tt
%select the times in boat_counts that match detections times with tolerance
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
Mathieu NOE 11 Dec 2020
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;

댓글을 달려면 로그인하십시오.





Community Treasure Hunt

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

Start Hunting!

Translated by