How to find a list of dates from a timetable?

14 views (last 30 days)
Hi!
I have a long timetable (Date_Captured.mat, attched) that contains 28805 different dates.
....
....
....
I want to find out specific 764 dates (Date_to_find.mat, attched) from the timetable.
....
....
....
Can anyone please tell me how can I do that?

Accepted Answer

Star Strider
Star Strider on 15 Feb 2023
Try this —
LD1 = load(websave('Date_Captured','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1296975/Date_Captured.mat'));
Date_Captured = LD1.Date_Captured
Date_Captured = 28805×2 timetable
TimeSeries HourSeries HeightSeries ___________ __________ ____________ 01-Jan-1984 {'09:00'} 0.216 01-Jan-1984 {'10:00'} 0.487 02-Jan-1984 {'09:00'} -0.009 02-Jan-1984 {'10:00'} 0.279 03-Jan-1984 {'09:00'} -0.186 03-Jan-1984 {'10:00'} 0.066 04-Jan-1984 {'09:00'} -0.313 04-Jan-1984 {'10:00'} -0.108 05-Jan-1984 {'09:00'} -0.408 05-Jan-1984 {'10:00'} -0.239 06-Jan-1984 {'09:00'} -0.479 06-Jan-1984 {'10:00'} -0.338 07-Jan-1984 {'09:00'} -0.514 07-Jan-1984 {'10:00'} -0.41 08-Jan-1984 {'09:00'} -0.494 08-Jan-1984 {'10:00'} -0.448
LD2 = load(websave('Date_to_find','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1296980/Date_to_find.mat'));
Date_to_find = LD2.Date_to_find
Date_to_find = 764×2 timetable
Time Var1 Var2 __________ _____ _____________ 1984-05-02 0.12 {'landsat_5'} 1984-06-03 18.49 {'landsat_5'} 1984-06-19 0 {'landsat_5'} 1984-09-23 1.49 {'landsat_5'} 1984-10-09 47.1 {'landsat_5'} 1984-10-25 7.27 {'landsat_5'} 1984-11-10 46.36 {'landsat_5'} 1984-11-26 0.08 {'landsat_5'} 1985-01-29 0.11 {'landsat_5'} 1985-04-19 71.61 {'landsat_5'} 1985-06-22 1.53 {'landsat_5'} 1985-08-09 0 {'landsat_5'} 1985-10-12 0 {'landsat_5'} 1985-10-28 0 {'landsat_5'} 1986-01-16 16.37 {'landsat_5'} 1986-02-01 43.73 {'landsat_5'}
[yc,mc,dc] = ymd(Date_Captured.TimeSeries);
[yf,mf,df] = ymd(Date_to_find.Time);
Lv = ismember([yc,mc,dc],[yf,mf,df],'rows');
Hits = nnz(Lv)
Hits = 1539
Result = Date_Captured(Lv,:)
Result = 1539×2 timetable
TimeSeries HourSeries HeightSeries ___________ __________ ____________ 02-May-1984 {'09:00'} -0.428 02-May-1984 {'10:00'} -0.224 03-Jun-1984 {'09:00'} -0.535 03-Jun-1984 {'09:30'} -0.51 03-Jun-1984 {'10:00'} -0.485 19-Jun-1984 {'09:00'} -0.338 19-Jun-1984 {'10:00'} -0.39 19-Jun-1984 {'10:24'} -0.3755 23-Sep-1984 {'09:00'} 0.401 23-Sep-1984 {'10:00'} 0.646 23-Sep-1984 {'10:54'} 0.673 09-Oct-1984 {'09:00'} 0.026 09-Oct-1984 {'10:00'} 0.283 25-Oct-1984 {'09:00'} -0.217 25-Oct-1984 {'10:00'} 0.154 10-Nov-1984 {'09:00'} -0.224
.

More Answers (2)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 15 Feb 2023
An alternative solution:
D1 = load('Date_Captured.mat').Date_Captured;
D2 = load('Date_to_find.mat').Date_to_find;
D2_Date = datetime(D2.Time, 'Format','dd-MMM-uuuu');
DIF_DATES = intersect(D1.TimeSeries, D2_Date);
DALL = D1.TimeSeries(DIF_DATES) % All selected dates
DALL = 1539×1 datetime array
02-May-1984 02-May-1984 03-Jun-1984 03-Jun-1984 03-Jun-1984 19-Jun-1984 19-Jun-1984 19-Jun-1984 23-Sep-1984 23-Sep-1984 23-Sep-1984 09-Oct-1984 09-Oct-1984 25-Oct-1984 25-Oct-1984 10-Nov-1984 10-Nov-1984 26-Nov-1984 26-Nov-1984 29-Jan-1985 29-Jan-1985 19-Apr-1985 19-Apr-1985 22-Jun-1985 22-Jun-1985 22-Jun-1985 09-Aug-1985 09-Aug-1985 12-Oct-1985 12-Oct-1985
DS_DATA = D1(DIF_DATES, :) % All selected data w.r.t the selected dates
DS_DATA = 1539×2 timetable
TimeSeries HourSeries HeightSeries ___________ __________ ____________ 02-May-1984 {'09:00'} -0.428 02-May-1984 {'10:00'} -0.224 03-Jun-1984 {'09:00'} -0.535 03-Jun-1984 {'09:30'} -0.51 03-Jun-1984 {'10:00'} -0.485 19-Jun-1984 {'09:00'} -0.338 19-Jun-1984 {'10:00'} -0.39 19-Jun-1984 {'10:24'} -0.3755 23-Sep-1984 {'09:00'} 0.401 23-Sep-1984 {'10:00'} 0.646 23-Sep-1984 {'10:54'} 0.673 09-Oct-1984 {'09:00'} 0.026 09-Oct-1984 {'10:00'} 0.283 25-Oct-1984 {'09:00'} -0.217 25-Oct-1984 {'10:00'} 0.154 10-Nov-1984 {'09:00'} -0.224
numel(DS_DATA(:,1)) % Number of selected data points/pairs
ans = 1539

Seth Furman
Seth Furman on 14 Mar 2023
You can index into a timetable more concisely by simply passing the target row-times as row indices.
Load data
load(websave('Date_Captured','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1296975/Date_Captured.mat'));
load(websave('Date_to_find','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1296980/Date_to_find.mat'));
Shift all row-times to the start of the current date
(This step is unnecessary if you already know that your datetimes have zeroes for hours, minutes, seconds, etc.)
Date_Captured.Properties.RowTimes = dateshift(Date_Captured.Properties.RowTimes,"start","day","current");
Date_to_find.Properties.RowTimes = dateshift(Date_to_find.Properties.RowTimes,"start","day","current");
Index the timetable by the target row-times
Date_Captured(Date_to_find.Properties.RowTimes,:)
ans = 1539×2 timetable
TimeSeries HourSeries HeightSeries ___________ __________ ____________ 02-May-1984 {'09:00'} -0.428 02-May-1984 {'10:00'} -0.224 03-Jun-1984 {'09:00'} -0.535 03-Jun-1984 {'09:30'} -0.51 03-Jun-1984 {'10:00'} -0.485 19-Jun-1984 {'09:00'} -0.338 19-Jun-1984 {'10:00'} -0.39 19-Jun-1984 {'10:24'} -0.3755 23-Sep-1984 {'09:00'} 0.401 23-Sep-1984 {'10:00'} 0.646 23-Sep-1984 {'10:54'} 0.673 09-Oct-1984 {'09:00'} 0.026 09-Oct-1984 {'10:00'} 0.283 25-Oct-1984 {'09:00'} -0.217 25-Oct-1984 {'10:00'} 0.154 10-Nov-1984 {'09:00'} -0.224

Categories

Find more on Line Plots 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!