Hi Niklas,
Firstly, the difference in the two surf plots is because the matrix 'y' is different in both the cases.
To understand the difference between 'surf' and 'plot3', take a look at the following example. (I have renamed 'y' as 'y1' and 'y2' as both the values are different). Let's start with the second method.
[x,y2] = meshgrid(-1:0.1:1);
z = x;
plot3(x,y2,z,'-o')
figure
surf(x,y2,z)
Output:
For both plot3 and surf, the corresponding points in the x, y2 and z matrices are plotted. Then, in 'plot3', all points corresponding to the first column of the matrices are joined, those corresponding to the second column of the matrices are joined and so on, thus giving us the first plot shown above. In 'surf', along with joining the columns, the points corresponding to the rows of the matrices are also joined giving us a surface as shown above in the second plot.
Now, coming to the first method.
[x] = meshgrid(-1:0.1:1);
y1 = x.^2;
z = x;
plot3(x,y1,z,'-o')
figure
surf(x,y1,z)
Output:
Similar to the previous method, for both plot3 and surf, the corresponding points in the x, y1 and z matrices are plotted. Now, in 'plot3', the points corresponding to the same column of the matrices should be joined. But, if you look at the matrices, you will find that for each matrix, all the rows in a column have the same value, hence it is a single point, and therefore there is no line - refer to the first plot shown above. In 'surf',as usual, the points corresponding to the rows of the matrices are joined, which in this case gives us a curve as we are just joining single points together.
For additional information on the functions, refer to the following links: meshgrid, surf, plot3 Hope this helps!
Thanks,
Divija