MATLAB: Creating a 3d surface plot

3dplotsurface

I have several x,y coordinates and an associated z-value for each x,y coordinate set. I would like to generate a 3d plot of these points, preferably with a mesh-like surface but am having trouble setting it up. I currently have three Nx1 vectors, one for the x-coordinates, one for the y-coordinates, and one for the z-values. How would I go about setting this plot up? The x,y coordinates are not in a nice rectangular grid, so meshgrid hasn't worked for me so far. Thanks, Reed

Best Answer

TriScatteredInterp Here's an example (taken from the doc):
% Make some fake vector data
x = rand(100,1)*4-2;
y = rand(100,1)*4-2;
z = x.*exp(-x.^2-y.^2);
% Put data onto a grid
[qx,qy] = meshgrid(linspace(min(x),max(x)),linspace(min(y),max(y)));
F = TriScatteredInterp(x,y,z);
qz = F(qx,qy);
surf(qx,qy,qz)