First minimum larger than zero

Hi,
I'd like to know the first index (and eventually the value) of the minimum element larger than zero in a vector.
Exemple : a=[14,9,4,-1,-6,-11,9,4,-1] , I look for "3" (and eventually the value = 4)
Any suggestion is kindly appreciated
thanks
ph

 Respuesta aceptada

KSSV
KSSV el 7 de Feb. de 2022
a=[14,9,4,-1,-6,-11,9,4,-1] ;
[val,idx] = min(abs(a))
val = 1
idx = 4

5 comentarios

ph
ph el 7 de Feb. de 2022
Thanks KSSV, but nope: that's index "4" and value "-1". I look for index "3" and value "4"
a=[14,9,4,-1,-6,-11,9,4,-1] ;
a(a<=0) = NaN ;
[val,idx] = min(a)
val = 4
idx = 3
ph
ph el 7 de Feb. de 2022
Ok thanks, that's working!
KSSV
KSSV el 7 de Feb. de 2022
Thanks is accepting/ voting the answer. :)
ph
ph el 7 de Feb. de 2022
Okok, needed to figure it out. Then you can edit the first answer with the comment you did after ;-)

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2020b

Etiquetas

Preguntada:

ph
el 7 de Feb. de 2022

Comentada:

ph
el 7 de Feb. de 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by