Implicit loop or break for large data set
Show older comments
Hi,
I am not very experienced with MATLAB and am trying to figure out the following situation. I have two large data sets, each a column of time information which is increasing. I want to find the indices of vector 1 that occur x seconds after an entry in vector 2, and return the indices of those locations in vector 2 as well.
My approach is that I have column vectors A and B, each with >2,000,000 data points but they are not the same size. Let us say I want the ones in B that occur within 1 s after A. So I have:
Atol = A +1 <-- this can be the maximum that the element in B can be, where the minimum is A. Then:
for i = 1:L1 (where L1 is length of A)
indx1 = (B >= A(i) & B <= Atol(i) )
end
And then to find the ones in A, I would do the same but the other way around.
for i = 1:L2
indx2 = (A <= B(i) & A>= Btol(i) ) where Btol is B-1
end
This would take forever to run however simply because of the large sets of data. Is there a way I can run this faster? I was thinking of implementing a break so that once I find one index, I stop and run through starting from that point since the answer for the second element will be later than the one for the first element, and so on. I have tried to implement this but it does not work. Alternatively, I have read that implicit loops are faster, but I cannot get this working either.
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!