MATLAB: Matlab Error (Z must be a matrix, not a scalar or vector.)

linear algebra

Hello
I was trying to plot using the following code but i get this error. Can someone help me please? Thank You
x = -2.5:.1:2.5;
y = -2.5:.1:2.5;
[X,Y] = meshgrid(x,y);
z = 2*sin(x.*y);
mesh(x,y,z)
grid on
hold on
Error using mesh (line 76) Z must be a matrix, not a scalar or vector.

Best Answer

Is this what you want?
x = -2.5:.1:2.5;
y = -2.5:.1:2.5;
[X,Y] = meshgrid(x,y);
Z = 2*sin(X.*Y);
mesh(X,Y,Z)
grid on
hold on
George Papazafeiropoulos