Effacer les filtres
Effacer les filtres

How to finding the second closest number in matrix?

1 vue (au cours des 30 derniers jours)
Yuli Hartini
Yuli Hartini le 4 Jan 2017
Modifié(e) : Adam le 4 Jan 2017
I have a matrix looks like this:
A = [1990;1993;1998;2001;2004 ]
and I would like to find the closest value to f=1999 (in this case the first closest value is certainly 1998), but how can I find the second closest value (2001) after I found the first value, and then find the third value (2004), etc.
Thanks

Réponses (1)

Adam
Adam le 4 Jan 2017
Modifié(e) : Adam le 4 Jan 2017
[~,idx] = sort( abs( A - 1999 ) );
A( idx )
will give you all of them in order.

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by