I am attaching an example variable and the answer your code should result in should be 175 or the 174 index.
closest value to zero excluding the first one?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ali Almakhmari
le 12 Jan 2023
Commenté : Bruno Luong
le 12 Jan 2023
If given a long vector of values. How can I find the index of the closest value to zero excluding the first value of the vector out of our list of stuff to search for
2 commentaires
Réponse acceptée
Ali Almakhmari
le 12 Jan 2023
1 commentaire
Bruno Luong
le 12 Jan 2023
That is NOT your question asks for, that is first consecutive points where 0 is cross from positive to negative.
Plus de réponses (2)
Bora Eryilmaz
le 12 Jan 2023
Modifié(e) : Bora Eryilmaz
le 12 Jan 2023
load('var.mat')
[~,I] = sort(abs(dis_y), 'ascend');
% Closest value to 0:
dis_y(I(1))
% Second closest value to 0:
dis_y(I(2))
2 commentaires
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!