MATLAB: Error using contour: Z must be at least a 2×2 matrix.

contour

What's the problem with the following code?
f=input('enter function: ','s');
f = str2func(['@(x,y)' vectorize(f)]);
[X,Y]=meshgrid(-10:.5:10);
contour(X,Y,f(x,y));
When I enter sin(x)+cos(y) the following error occurs:
Z must be at least a 2×2 matrix.

Best Answer

Your typo
Should be:
contour(X,Y,f(X,Y));