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

numbervector

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.

Best Answer

A(A==0)=inf
[~,idx]=min(A)