MATLAB: Switch/case command function

functionswitch

I'm trying to create a function with the switch /case commands and run it from another program satisfying certain criteria. The files are in the same folder but I'm not sure how to lay out the function and call it for that matter. Here is my function file:
function input = g(x) switch input case x < -pi disp('-1') case g >= -1 && g<= pi cos(g) case g > pi disp('-1')
end
Thanks for you help

Best Answer

Here is the function that does it (hopefully it is what you want)
function y=g(x)
if x < -pi
y=-1;
elseif (x >= -pi && x<=pi)
y=cos(x);
elseif x > pi
y=-1;
end
Related Question