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/
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.