MATLAB: How to declare a function having bounds

function declarationMATLAB

example-
f(x)= 0 x<0
x 0<x<1
-1 x>1

Best Answer

One way,
f=@(x) x.*(x>=0 & x<=1) - (x>1)