Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a surf plot in MATLAB with irregularly spaced data?

Tags:

plot

matlab

3d

I know I can create a 3D surface plot in MATLAB by doing:

x = linspace(1,10,100);
y = linspace(10,20,100);

[X Y] = meshgrid(x,y);

Z = X * Y;

surf(X,Y,Z);

But this requires that all the nodes for the height map generated line up. I have a set of data which has arbitrary points (x,y) and a height (z). Is there a simple way to plot a graph which will generate a surface between the points in a similar fashion to surf?

like image 295
JP. Avatar asked May 17 '10 09:05

JP.


People also ask

How do you plot a surf function in Matlab?

surf( Z ) creates a surface plot and uses the column and row indices of the elements in Z as the x- and y-coordinates. surf( Z , C ) additionally specifies the surface color. surf( ax ,___) plots into the axes specified by ax instead of the current axes. Specify the axes as the first input argument.

What is the difference between mesh and surf in Matlab?

surf() and mesh() both create Chart Surface Objects in current releases. surf() turns on face coloring by default and uses black edges by default, whereas mesh() turns face coloring off by default and uses colored edges by default.

How do I change the surf view in Matlab?

Change the View Using a Vector Change the view by specifying v as the x- y- and z-coordinates of a vector, and return the new azimuth and elevation angles. The new angles are based on a unit vector pointing in the same direction as v .

Which two functions can be utilized together to plot a surface in 3 D using Matlab?

Forming the sinc function and plotting Z with mesh results in the 3-D surface.


2 Answers

Appologies, after some hunting I managed to answer my own question:

You can use the trisurf function:

tri = delaunay(x,y);
trisurf(tri,x,y,z);

If you have dense data you will want to do shading interp (or another value, check doc shading) so you don't get a black blob due to the grid.

like image 126
JP. Avatar answered Oct 24 '22 20:10

JP.


It looks like you've found your answer by using DELAUNAY and TRISURF to generate and plot a triangulated surface.

As an alternative, you could also fit a regularly-spaced grid to your nonuniformly-spaced points in order to generate a surface that can be plotted with the SURF command. I discuss how this can be done using the TriScatteredInterp class (or the deprecated function GRIDDATA) in my answer to this other question on SO.

like image 26
gnovice Avatar answered Oct 24 '22 20:10

gnovice