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

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)
  • Add a Comment

    Your email address will not be published. Required fields are marked *