MATLAB: Error keeps being displayed: “Z must be a matrix, not a scalar or vector”

3-d ploterror

I need to make a 3-D plot of the function z = sin(t)/t, where t = sqrt(x^2 + y^2) in the domain x[-10:10] and y[-10:10].
This is what I have for my script:
x = -10:2:10;
y = -10:2:10;
[X,Y] = meshgrid(x,y);
t = sqrt(x.^2 + y.^2);
z = sin(t)./t;
mesh(X,Y,z)
Unfortunately I keep getting the error message:
"Error using mesh (line 76) Z must be a matrix, not a scalar or vector"

Best Answer

x = -10:2:10;
y = -10:2:10;
[X,Y] = meshgrid(x,y)
t = sqrt(X.^2 + Y.^2); % X,Y instead of x,y
z = sin(t)./t;
mesh(X,Y,z)