Intersect two datetime vectors with 1min tolerance
    13 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
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 Commenti
Risposte (1)
  Seth Furman
    
 il 24 Feb 2022
        
      Modificato: Seth Furman
    
 il 25 Feb 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 Commenti
Vedere anche
Categorie
				Scopri di più su Matrix Indexing in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

