Clear Filters
Clear Filters

Get the nearest value when two arrays are logged at different time.with different logging rates

1 view (last 30 days)
Hi! I have two data sets one is logged at 200ms and other is logged at 1 sec. Lets call the data set logged at 1 sec as 'x' and the one logged at 200ms as 'y'. Now what is what value in x will be the closest match to the values in y.
The size of 'y' is 360313x1 and the size of 'x' is 71885x1. Please let me know if any more info will be needed. My apologies I cant share the real data set.

Accepted Answer

Jan
Jan on 12 Dec 2017
y = rand(360313, 1)
x = rand(71885, 1);
index = zeros(size(x));
for k = 1:numel(x)
[~, index(k)] = min(abs(y - x(k)));
end
Does this match your problem?
  2 Comments
sc1991
sc1991 on 14 Dec 2017
Hi! Jan I just saw an issue. So, your programs works fine but I have one sensor that measures speed and I when its trying to find the closest value it will check for any values that's closest to it. But since one is logging at 200ms and the other is logging at 1 sec and they both start at different time. I want that ones we have found the match for first index where they match it just increments and never go below that first match index. will you be able to help?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!