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?
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Ali Almakhmari
il 12 Gen 2023
Commentato: Bruno Luong
il 12 Gen 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
Risposta accettata
Ali Almakhmari
il 12 Gen 2023
1 Commento
Bruno Luong
il 12 Gen 2023
That is NOT your question asks for, that is first consecutive points where 0 is cross from positive to negative.
Più risposte (2)
Bora Eryilmaz
il 12 Gen 2023
Modificato: Bora Eryilmaz
il 12 Gen 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))
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!