Problem2 Surface plots Plot the surface generated by Z sinxc
Solution
Use meshgrid to generate a grid of X and Y data. Plot the surface mesh and plots.
Sample program to illustrate the different functions:
Example – Displaying Nonuniform Data on a Surface
This example evaluates the sinc function at random points within a specific range and then generates uniformly sampled data for display as a surface plot. The process involves these tasks:
Find below some of the information representing gridded data as surface and mesh plots.
Functions for Plotting Data Grids
MATLAB graphics defines a surface by the z-coordinates of points above a rectangular grid in the x-y plane. The plot is formed by joining adjacent points with straight lines. Surface plots are useful for visualizing matrices that are too large to display in numerical form and for graphing functions of two variables.
Function
Used to Create
mesh, surf
Surface plot
meshc, surfc
Surface plot with contour plot beneath it
meshz
Surface plot with curtain plot (reference plane)
pcolor
Flat surface plot (value is proportional only to color)
surfl
Surface plot illuminated from specified direction
surface
Low-level function (on which high-level functions are based) for creating surface graphics objects
Functions for Gridding and Interpolating Data
These functions are useful when you need to restructure and interpolate data so that you can represent this data as a surface.
Function
Used to Create
meshgrid
Rectangular grid in 2-D and 3-D space
griddata
Interpolate scattered data
griddedInterpolant
Interpolant for gridded data
scatteredInterpolant
Interpolate scattered data
Example: the Use of meshgrid
The use of meshgrid, consider the sin(r)/r or sinc function. To evaluate this function between -8 and 8 in both x and y, you need pass only one vector argument to meshgrid, which is then used in both directions.
The matrix R contains the distance from the center of the matrix, which is the origin. Adding eps prevents the divide by zero (in the next step) that produces Inf values in the data.
Forming the sinc function and plotting Z with mesh results in the 3-D surface.
Emphasizing Surface Shape
MATLAB provides a number of techniques that can enhance the information content of your graphs.
For example: the graph of the sinc function uses the same data as the previous graph, but employs lighting, view adjustments, and a different colormap to emphasize the shape of the graphed function (daspect, axis, view, camlight).
| Function | Used to Create | 
|---|---|
| mesh, surf | Surface plot | 
| meshc, surfc | Surface plot with contour plot beneath it | 
| meshz | Surface plot with curtain plot (reference plane) | 
| pcolor | Flat surface plot (value is proportional only to color) | 
| surfl | Surface plot illuminated from specified direction | 
| surface | Low-level function (on which high-level functions are based) for creating surface graphics objects | 
![Problem-2 Surface plots Plot the surface generated by Z sin(x)cos(x)e over the domain x E [-3, 3] and y E [-3,3]. Use meshgrid to generate a grid of X and Y da  Problem-2 Surface plots Plot the surface generated by Z sin(x)cos(x)e over the domain x E [-3, 3] and y E [-3,3]. Use meshgrid to generate a grid of X and Y da](/WebImages/39/problem2-surface-plots-plot-the-surface-generated-by-z-sinxc-1120288-1761596022-0.webp)
![Problem-2 Surface plots Plot the surface generated by Z sin(x)cos(x)e over the domain x E [-3, 3] and y E [-3,3]. Use meshgrid to generate a grid of X and Y da  Problem-2 Surface plots Plot the surface generated by Z sin(x)cos(x)e over the domain x E [-3, 3] and y E [-3,3]. Use meshgrid to generate a grid of X and Y da](/WebImages/39/problem2-surface-plots-plot-the-surface-generated-by-z-sinxc-1120288-1761596022-1.webp)
