Effacer les filtres
Effacer les filtres

selecting values of a vector

4 vues (au cours des 30 derniers jours)
dav
dav le 2 Avr 2013
Hi,
Is there a way to pick the element of a vector which is closest to 1.
Let's say A = [ 113; 14; 6; 43; 9; 2 ]
I was wondering if there's a method to pick the value which is closest to 1. which in this case is = 2
Thanks

Réponse acceptée

Walter Roberson
Walter Roberson le 2 Avr 2013
[minA, minidx] = min(abs(A - 1));
A(minidx)
  1 commentaire
dav
dav le 2 Avr 2013
thanks a lot!

Connectez-vous pour commenter.

Plus de réponses (0)

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!

Translated by