How to find a list of dates from a timetable?
    12 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Ashfaq Ahmed
      
 el 15 de Feb. de 2023
  
    
    
    
    
    Respondida: Seth Furman
    
 el 14 de Mzo. de 2023
            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?
0 comentarios
Respuesta aceptada
  Star Strider
      
      
 el 15 de Feb. de 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
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
[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)
Result = Date_Captured(Lv,:)
.
2 comentarios
Más respuestas (2)
  Sulaymon Eshkabilov
      
 el 15 de Feb. de 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
DS_DATA = D1(DIF_DATES, :)                         % All selected data w.r.t the selected dates
numel(DS_DATA(:,1))                                  % Number of selected data points/pairs  
  Seth Furman
    
 el 14 de Mzo. de 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,:)
0 comentarios
Ver también
Categorías
				Más información sobre Time Series Objects en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



