Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help
next up previous contents
Next: Generating solids from functions Up: Examples Previous: Displaying data from a

2D Interpolation

Most of matlab's 3D routines require the values to be on a regular 2D grid. Suppose you have some 3D coordinates contained in 3 vectors x, y and z but the (x,y) points don't lie on a regular grid. You can use plot3 to display the individual points, but to display surfaces you need to do more work
% first define a regular grid. Suppose the x and y values lie between
% 0 and 100, and that we want 20 grid-lines each way
steps = linspace(0,100,20);
[XI,YI] = meshgrid(steps, steps);

% now extrapolate - find z values for these grid points
ZI = griddata(x,y,z,XI, YI);
% display this mesh with the original data
mesh(XI,YI,ZI);
hold
plot3(x,y,z);
hold off

Matlab has 3D interpolation facilities too.



© Cambridge University Engineering Dept
Information provided by Tim Love
2006-07-24