Find the index of the lowest number greater than zero in a vector

20 views (last 30 days)
I would like to find the index of the lowest number greater than zero in a vector. ex: [0,0,4,5,0] The answer should be 3 because 4 is the third element.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 22 Aug 2016
A(A==0)=inf
[~,idx]=min(A)

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices 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!