MATLAB: I’m trying to create the own functions but I keep getting an error message

functionfunctionsunit step

I'm trying to create functions taken from my textbook to use later but I keep getting one of 2 error messages:
Unknown function or variable 'x'
or
not enough input arguments
function y = us(x)
y = (sign(x)+1)/2;
end
This is the code from the textbook so I'm assuming the code is fine and it must be some sort of error where I'm saving it
thanks in advance

Best Answer

The code itself looks okay. The problem is in how you invoke it. You cannot just press the green Run button for the function: you must invoke it from the command line or from other code, passing in values. For example going to the command line and invoking
us(-2:.5:2)