Download presentation
1
Introduction to Matlab:
Matlab Graphics 3D Graphics S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn
2
3D Graphics Topics Creating Mesh and Surface Plots
Viewing a Pseudocolor Matrix Creating Contour Plots Adding a Color-Bar Interpolating 3D Data
3
Mesh and Surface Plots Useful for displaying functions of 2 variables or to visualize large matrices Given a function f(x,y) of two variables: Assume that: » x=[-1:0.2:1]; y=[-1:0.2:1]; We can plot the function z as a mesh or surface plot
4
4/15/2017 Calculating xx Height = Length of y Row = Vector x
5
Generating xx in Matlab
» xx=ones(length(x),1)*x xx =
6
Calculating yy Length = Length of y Column = y Transpose
7
Generating yy in Matlab
» yy=y'*ones(1,length(y)) yy =
8
Find xx & yy Using Meshgrid
» [xx,yy] = meshgrid(x,y) xx = yy =
9
Find z Find z using element by element computations
» z=xx.*exp(-xx.^2-yy.^2) z =
10
Mesh Plot z » mesh(x,y,z) Finer increments of x and y will smooth the surface
11
Mesh for a Larger x & y Create a new mesh plot complete with labels
» [xx,yy]=meshgrid(x,y); » z=xx.*exp(-xx.^2-yy.^2); » mesh(x,y,z) » title('Larger Mesh'); » xlabel('X Data'); » ylabel('Y Data'); » zlabel('z=xx.*exp(-xx.^2-yy.^2)');
12
Surface Plot of z » surf(x,y,z)
Plots the colored parametric surface where color is proportional to surface height
13
Pcolor pseudocolor or "checkerboard" plot of matrix
» pcolor(x,y,z) pseudocolor or "checkerboard" plot of matrix The values of the elements specify the color in each cell of the plot
14
Contour Plots contour plot of matrix where z contains heights above a plane Number of Contour Lines » contour(x,y,z,16); » title('Contour');
15
Displaying Contour Heights
To write the values identifying the heights: » cs=contour(x,y,z,16); » clabel(cs); » title('Contour Heights');
16
Meshc Contour Plots meshc is same as mesh except that a contour plot is drawn beneath the mesh » meshc(x,y,z) Only works for surfaces defined on a rectangular grid
17
Adding a Colorbar colorbar adds a vertical line (color scale) to show the contour plots
18
3D Interpolation Rough or scattered data can be interpolated using mesh The original data is plotted as a mesh by: » x=[-3:3]; y=[1:5]; » [xx, yy]=meshgrid(x,y); » z= xx + yy; » mesh(x,y,z); » title('Original Mesh Grid'); » xlabel('X Data'); ylabel('y Data'); » zlabel('z = xx + yy');
19
Mesh of Rough Data Original Course Surface where: x = [-3:3] y = [1:5]
z = xx+yy
20
Interpolation of Data The original mesh from the data is can be improved by creating interpolated values using griddata: » xi=[-3:0.5:4]; % Interpolated x axis » yi=[ 0:0.2:5]; % Interpolated y axis » [xxi,yyi]=meshgrid(xi,yi); » % zi = interpolated values » zi=griddata(xx,yy,z,xxi,yyi); » mesh(xxi,yyi,zi); % Better surface » title('Interpolated Mesh Grid'); » xlabel('X Data'); ylabel('y Data'); » zlabel('z = xx + yy');
21
3D Interpolation Plot Interpolated Smooth Surface where:
xi = [-3:0.5:4] yi = [ 0:0.2:5]
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.