MATLAB: Defining (not plotting) a Piecewise Function with If, Else Statements

piecewise

I have the following, which doesn't work. Does anyone have any recommendations? I need a simple piecewise constant function.
function [ x ] = m0( var1 )
if 0 <= var1 < 1/3 x = 1/sqrt(2); else if 1/3 <= var1 < 2/3 x = 0; else x = -1/sqrt(2); end end end

Best Answer

if 0 <= var < 1/3
is not valid syntax in matlab, you need to use logical operators:
if var1 >= 0 && var1 < 1/3
x = 1/sqrt(2);
elseif var1 >= 1/3 && var1 < 2/3
x = 0;
else
x = -1/sqrt(2);
end