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 views (last 30 days)
Show older comments
Ali Almakhmari
on 12 Jan 2023
Commented: Bruno Luong
on 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
Accepted Answer
Ali Almakhmari
on 12 Jan 2023
1 Comment
Bruno Luong
on 12 Jan 2023
That is NOT your question asks for, that is first consecutive points where 0 is cross from positive to negative.
More Answers (2)
Bora Eryilmaz
on 12 Jan 2023
Edited: Bora Eryilmaz
on 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))
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!