Is there any command / function to tell what the value of this list that is closest to 20 (for example)?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nuno Simões
le 21 Avr 2014
Commenté : Nuno Simões
le 21 Avr 2014
Hi,
I have, for example, the following list of values.
102.0
105.7
116.5
128.3
134.0
137.3
0.080
0.160
0.200
0.240
0.320
0.390
0.400
0.470
0.550
0.600
Is there any command / function to tell what the value of this list that is closest to 20 (for example)?
Thanks
0 commentaires
Réponse acceptée
the cyclist
le 21 Avr 2014
Modifié(e) : the cyclist
le 21 Avr 2014
Not a single command, but simple enough. Assume x is your vector.
[minDiff,idx] = min(abs(x-20));
closestValue = x(idx);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with MATLAB 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!