I need a function which returns 0 if the argument is negative

3 visualizaciones (últimos 30 días)
Elia Paini
Elia Paini el 19 de Mzo. de 2022
Editada: Stephen23 el 15 de Dic. de 2022
Hi, I need a function in Matlab which returns 0 if the argument is negative:
f(x) = 0 if x < 0
f(x) = f(x) if x > 0
How can I do?
Thank you!
  1 comentario
Stephen23
Stephen23 el 15 de Dic. de 2022
Editada: Stephen23 el 15 de Dic. de 2022
MATLAB already has such a function, it is called MAX():
max(0,x)

Iniciar sesión para comentar.

Respuestas (1)

Torsten
Torsten el 19 de Mzo. de 2022
g = @(x) (x > 0).*f(x)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by