Q:

Incorrect graph when trying to plot z = x + y with MATLAB

I am attempting to plot 3D surfaces in MATLAB, and I made use of meshgrid, similar to what the MATLAB tutorials said here: http://www.mathworks.com/help/matlab/ref/meshgrid.html
I wrote a very simple three line script that I believed would produce the surface z = x + y and it is as follows:
[x , y] = meshgrid( linspace( 0 , 10 , 10 ) , linspace( 0 , 10 , 10 ) );
z = x + y;
surf( [ x , y , z] );

From what I understand, line 1 produces all combinations of (x,y) coordinates evenly spaced from 0 to 10. Then line 2 just applies the formula z = x + y to that exhaustive list of combinations. Then line 3 just plots all the (x, y, z) points.
But I got the following "thing" as output:

I'm pretty sure the graph in the above picture is not z = x + y, and I have no clue why there aren't two axes going up to maximum value 10. 
Still, I find the script too simple and couldn't see anything wrong with it. Could anyone point out where I overlooked something? Thank you.

A:

Your syntax for generating the 3D coordinates is right.  Your call to surf is incorrect.  What you actually need to do is separate x, y and z into three separate parameters:
surf(x,y,z);

When you do that, you get this surface.  Take note that the figure generated was using MATLAB R2013a, so the colour map shown is not the parula colour map that is available as of R2014b and up, but the surface will be the right one that is what you're looking for:

... now why do you need to separate your x, y and z points to create the surface?  The reason why is because doing [x,y,z] means that you are concatenating the x, y and z coordinates into a single 2D signal, and so what's happening is that you are creating a 2D signal that is 10 x 30.  Calling surf with this single 2D array automatically assumes that the x values span from 1 to 30 and the y values span from 1 to 10 and those are the 2D grid of values that span the axis of your surf plot in conjunction with the z values shown, where the z values originate from the concatenated matrix created earlier.  If you look at the plot you generated, you can see the x values are spanning from 1 to 30, and that's obviously not what you want.
You need to separate the x, y and z values to achieve the desired plane.

