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

2 vues (au cours des 30 derniers jours)
Elia Paini
Elia Paini le 19 Mar 2022
Modifié(e) : Stephen23 le 15 Déc 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 commentaire
Stephen23
Stephen23 le 15 Déc 2022
Modifié(e) : Stephen23 le 15 Déc 2022
MATLAB already has such a function, it is called MAX():
max(0,x)

Connectez-vous pour commenter.

Réponses (1)

Torsten
Torsten le 19 Mar 2022
g = @(x) (x > 0).*f(x)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by