nearest value but bigger nearest

8 次查看(过去 30 天)
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!

采纳的回答

Andrei Bobrov
Andrei Bobrov 2016-9-15
k = bsxfun(@minus,A(:)',B(:));
k(k >= 0) = -inf;
[~,ii] = max(k);
ii(all(k == -inf)) = 0;
  1 个评论
Jessica Jacobs
Jessica Jacobs 2020-2-11
How do you change this to find the nearest value less than (rather than greater than)?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Elementary Math 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by