MATLAB: ERROR: Z must be a matrix, not a scalar or vector.

mesh

What's the problem with the following code?
syms x y;
f=input('enter function: ','s');
f = symfun(eval(f), [x y]);
[X,Y]=meshgrid(-10:1:10);
mesh(f);
when i run the above code after entering a function the following error occurs:
Z must be a matrix, not a scalar or vector.

Best Answer

There is no reason to use the Symbolic Math Toolbox here. Core MATLAB fiunctions will work.
The Code
f=input('enter function: ','s')
% f = 'x.^2 + sin(y)'; % Test Function
f = str2func(['@(x,y)' f]);
[X,Y]=meshgrid(-10:1:10);
mesh(X,Y,f(X,Y));