How to chose the nearest value
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Matt Learner
le 23 Fév 2012
Modifié(e) : Mohammad Monfared
le 21 Oct 2013
Suppose I have a point at location (3,800) and for this point, I have to select the nearest point. I have 3 points say (2,790), (3,770) and (2.5,780). How to find which one out of these three points is nearest to the given point (3,800)?
0 commentaires
Réponse acceptée
nanren888
le 23 Fév 2012
So where are you stuck? Give us a hint of what you're thinking so far. Maybe calculate the distances & take the mimimum?
>> p=[3;800];
q = [2,790;3,770;2.5,780].';
d = sum((p*ones([1,size(q,2)])-q).^2,1);
[~,minI] = min(d)
minI =
1
1 commentaire
Jan
le 23 Fév 2012
Solving homework questions is no benefit for the author or the forum.
REPMAT or BSXFUN are smarter than a multiplication with ONES.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing 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!