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?
19 次查看(过去 30 天)
显示 更早的评论
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
采纳的回答
Ali Almakhmari
2023-1-12
1 个评论
Bruno Luong
2023-1-12
That is NOT your question asks for, that is first consecutive points where 0 is cross from positive to negative.
更多回答(2 个)
Bora Eryilmaz
2023-1-12
编辑:Bora Eryilmaz
2023-1-12
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))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!