MATLAB: How to evaluate a user-input trigonometric function

trigonometric functionsuser input

I'm not entirely sure how to explain this but here is the question:
My main issue is I don't know how to use eval when using a user-input trigonometric function. (I don't really need help with the graphing part).
This is my attempt:
n = input('Enter a positive number n: ');
x = linspace(0, n, 1000)
trigfunc = input('Enter a trigonometric function: ', 's');
eval('trigfunc(x)')

Best Answer

n=input('enter a pos num\n');
x=linspace(0,n,1000);
trigfunc=input('Enter 1=sin(x), 2=cos(x), 3=tan(x), 4=cot(x)\n');
if(trigfunc==1)
y=sin(x);
plot(x,y);title(['sin(x) from [0 ' ,num2str(n), ']'])
elseif(trigfunc==2)
y=cos(x);
plot(x,y);title(['cos(x) from [0 ' ,num2str(n), ']'])
elseif(trigfunc==3)
y=tan(x);
plot(x,y);title(['tan(x) from [0 ' ,num2str(n), ']'])
elseif(trigfunc==4)
y=cot(x);
plot(x,y);title(['cot(x) from [0 ' ,num2str(n), ']'])
end