필터 지우기
필터 지우기

Intersect two datetime vectors with 1min tolerance

조회 수: 5 (최근 30일)
Arthur Romeu
Arthur Romeu 2022년 2월 23일
편집: Seth Furman 2022년 2월 25일
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.

답변 (1개)

Seth Furman
Seth Furman 2022년 2월 24일
편집: Seth Furman 2022년 2월 25일
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))
C = 205115×1 datetime array
31-May-2021 12:59:00 31-May-2021 13:00:00 31-May-2021 13:01:00 31-May-2021 13:02:00 31-May-2021 13:03:00 31-May-2021 13:04:00 31-May-2021 13:05:00 31-May-2021 13:06:00 31-May-2021 13:07:00 31-May-2021 13:08:00 31-May-2021 13:09:00 31-May-2021 13:10:00 31-May-2021 13:11:00 31-May-2021 13:12:00 31-May-2021 13:13:00 31-May-2021 13:14:00 31-May-2021 13:15:00 31-May-2021 13:16:00 31-May-2021 13:17:00 31-May-2021 13:18:00 31-May-2021 13:19:00 31-May-2021 13:20:00 31-May-2021 13:21:00 31-May-2021 13:22:00 31-May-2021 13:23:00 31-May-2021 13:24:00 31-May-2021 13:25:00 31-May-2021 13:26:00 31-May-2021 13:27:00 31-May-2021 13:28:00

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by