MATLAB Answers

Thar
0

nearest value but bigger nearest

Asked by Thar
on 15 Sep 2016
Latest activity Answered by Andrei Bobrov
on 15 Sep 2016
Hi all! I have two matrix A(1:250,1)and B(1:50,1). I want to find for all values of A the nearest value in B, but the nearest bigger than the value of A. I have the function
[~, ii] = min(abs(bsxfun(@minus,A(:, 1)',B(:,1))));
but this function find only the nearest value. Smaller or bigger.
Thank you!

  0 Comments

Sign in to comment.

1 Answer

Answer by Andrei Bobrov
on 15 Sep 2016
 Accepted Answer

k = bsxfun(@minus,A(:)',B(:));
k(k >= 0) = -inf;
[~,ii] = max(k);
ii(all(k == -inf)) = 0;

  0 Comments

Sign in to comment.