Intersect two datetime vectors with 1min tolerance
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello everyone, I am currently trying to find the common values between two datetime vectors (attached) and return their indexes on their respective lists with a tolerance of +-1min. I was trying to approach this using intersect as so:
[COMPS_data_CGGPBR,i_CGGPBR,i_PBR] = intersect(data_tracking_CGGPBR,data_tracking_PBR, 'Rows');
However, I don't know how to add the 1 minute tolerance that I need. It is a shame, because this function gives exactly what I need: the common datetime and the indexes that they first appear on each list.
Since my thinking is apparently leading nowhere, what can I use to solve this problem? I have tried simple loops, but it would take me ~250 days to calculate it all.
Thanks in advance,
Arthur.
0 comentarios
Respuestas (1)
Seth Furman
el 24 de Feb. de 2022
Editada: Seth Furman
el 25 de Feb. de 2022
load(websave('data_tracking_PBR.mat', 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/904455/data_tracking_PBR.mat'));
load(websave('data_tracking_CGGPBR.mat', 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/904460/data_tracking_CGGPBR.mat'));
A = unique(data_tracking_PBR, "sorted");
B = unique(data_tracking_CGGPBR, "sorted");
tol = minutes(1);
i = 1;
j = 1;
ia = false(1, length(A));
ib = false(1, length(B));
while i <= length(A) && j <= length(B)
if abs(B(j)-A(i)) <= tol
ia(i) = true;
ib(j) = true;
if B(j) <= A(i)
j = j + 1;
else
i = i + 1;
end
elseif A(i) < B(j)-tol
i = i + 1;
else
j = j + 1;
end
end
C = union(A(ia), B(ib))
0 comentarios
Ver también
Categorías
Más información sobre Matrices and Arrays 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!