Sunday, 7 August 2016

MATLAB Programming 52 - 3D plots of functions


Three-Dimensional Plots


Three-dimensional plots basically display a surface defined by a function in two variables, g = f (x,y).
As before, to define g, we first create a set of (x,y) points over the domain of the function using the meshgrid command. Next, we assign the function itself. Finally, we use the surf command to create a surface plot.

The following example demonstrates the concept:


Use the peaks function to define XY, and Z as 25-by-25 matrices. Then, create a surface plot.



[X,Y,Z] = peaks(25);

figure
surf(X,Y,Z);


surf creates the surface plot from corresponding values in XY, and Z. If you do not define the color data C, then surf uses Z to determine the color, so color is proportional to surface height.




No comments:

Post a Comment