Department of Engineering

IT Services

3D Graphics

MATLAB can be used to plot 2-d functions e.g. 5x2 + 3y2 :


>> [x,y]=meshgrid(-1:0.1:1,-1:0.1:1);

>> z=5*x.^2+3*y.^2;
>> contour(x,y,z);
>> prism;
>> mesh(x,y,z)
>> surf(x,y,z)
>> view([10 30])
>> view([0 90])

The meshgrid function creates a `mesh grid' of x and y values ranging from -1 to 1 in steps of 0.1. If you look at x and y you might get a better idea of how z (a 2D array) is created. The mesh function displays z as a wire mesh and surf displays it as a facetted surface. prism simply changes the set of colours in the contour plot. view changes the horizontal rotation and vertical elevation of the 3D plot. The z values can be processed and redisplayed


>> mnz=min(min(z));

>> mxz=max(max(z));
>> z=255*(z-mnz)/(mxz-mnz);
>> image(z);
>> colormap(gray);

image takes interprets a matrix as a byte image. For other colormaps try help color.