Making Surface Plots From Scatter Data
04 Jun 2004
08 Jun 2004)
How to turn a collection of XYZ triplets into a surface plot.
%% Making Surface Plots From Scatter Data
% How do you turn a collection of XYZ triplets into a surface plot? This is
% the most frequently asked 3D plotting question that I got when I was in
% Tech Support.
%% Load the data
who -file seamount
% The problem is that the data is made up of individual (x,y,z)
% measurements. It isn't laid out on a rectilinear grid, which is what the
% SURF command expects. A simple plot command isn't very useful.
%% Little triangles
% The solution is to use Delaunay triangulation. Let's look at some
% info about the "tri" variable.
tri = delaunay(x,y);
% How many triangles are there?
[r,c] = size(tri);
%% Plot it with TRISURF
h = trisurf(tri, x, y, z);
%% Clean it up
l = light('Position',[-50 -15 29])
set(gca,'CameraPosition',[208 -50 7687])