Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help
next up previous contents
Next: Plotting experimental data Up: Graphics Previous: General

3D plots

There are many 3D options too, but again you still need to calculate all the coordinates.
 x=linspace(-1, 1, 10);
 y=linspace(-1, 1, 10);
 [X, Y]=meshgrid(x,y);
 Z= X.^2-Y.^2;
The meshgrid command creates 2 2D matrices, each with as many elements as there are grid-points. The X matrix has the x coordinates and the Y matrix the y coordinates. Then the z coordinate is calculated for each point and put in a Z matrix. Instead of mesh, surf could be used to display a facetted surface. Then the following can be done to add graduated colour and a key.
shading interp;

© Cambridge University Engineering Dept
Information provided by Tim Love