Match datetime within 2 seconds from two columns of different sizes
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi all,
I am trying to match datetimes to an accuracy of within 2 seconds of two columns of different sizes. I want to compare all the elements of one datetime column (this column has 3465 elements) with all the elements of the other datetime column (2450 elements) and create one variable with the elements of the first column which differ less than 2 minutes from any element of the 2nd column, and other variable with the elements of the 2nd column whitch differ less than 2 minutes from any element of 1st column.
The 2 columns have the format 'MM/dd/yyyy HH:mm:ss,
In the end my goal is to make a graphic with the datetime and other variable and to represent the dates that are very similar (less than 2 minutes), so I can compare how the other variable is behaving in the same dates.
1 Commento
SALAH ALRABEEI
il 14 Giu 2021
I think you already have asked before, and someone just answered. https://www.mathworks.com/matlabcentral/answers/837433-substract-all-elements-from-one-vector-minus-all-elements-from-other-vector?s_tid=answers_rc1-1_p1_MLT
Risposte (1)
Aghamarsh Varanasi
il 17 Giu 2021
Modificato: Aghamarsh Varanasi
il 17 Giu 2021
Hi,
To handle datetime data, you can use the datetime data type to save the data as a MATLAB variable. This helps you to compare two dates as follows:
d1 = '06/17/2021 10:30:05';
d2 = '06/17/2021 10:35:15';
date1 = datetime(d1, 'InputFormat', 'MM/dd/yyyy HH:mm:ss');
date2 = datetime(d2, 'InputFormat', 'MM/dd/yyyy HH:mm:ss');
var = [];
% check if the duration difference is less than 2 minutes
if date1.Minute < date2.Minute + 2 && date1.Minute > date2.Minute - 2
var = [var, [date1, date2]];
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Timetables in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!