nearest value but bigger nearest

3 vues (au cours des 30 derniers jours)
Thar
Thar le 15 Sep 2016
Commenté : Jessica Jacobs le 11 Fév 2020
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!

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Descriptive Statistics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by