How to filter out dates within a datetime list?
13 Ansichten (letzte 30 Tage)
Hi! I have two timetable containing hourly information from 2005 to 2019. The first one NOAA.mat is a 131472x1 timetable and the second one BUOY.mat is a 131274x1 timetable.
As you can see, there are some observation lost in the BUOY file. Can anyone please give me an idea on how to match the NOAA data with the BUOY data so they have the similar size? (i.e., I want to delete the extra observations from the NOAA data while keeping the rest of the time perfectly aligned.)
Any feedback will be greatly appreciated!!
Adam Danz am 27 Apr. 2023
Bearbeitet: Adam Danz am 27 Apr. 2023
Here are the steps you can take.
1. NOAA contains dates and durations in separate variables. Combine them into 1 datetime vector using
dt=dateshift(NOAA.N_Time,'start','day') + NOAA.N_Hr;
If you want, you can format it to see the full datetime values using
2. To find matching datetime values between the two vectors and to update the tables to only include rows with matching time stamps,
[~, NOAAidx, BUOYidx] = intersect(dt, BUOY.B_Time);
NOAA = NOAA(NOAAidx,:);
BUOY = BUOY(BUOYidx,:);
3. Verify sizes
size(NOAA) % 107630 x 1
size(BUOY) % 107630 x 1
Are the time stamps the same?
isequal(BUOY.B_Time, dateshift(NOAA.N_Time,'start','day') + NOAA.N_Hr)
ans = true