Download presentation
Published byDominic Hawkins Modified over 8 years ago
1
EEE 242 Computer Tools for Electrical Engineering
Lecture III Mustafa Karabulut
2
Lecture III Topics 3D line plots Mesh and surface plots
Use of meshgrid to produce 3D points
3
3D Line Plots
4
Creating mesh and surface plots
About Mesh and Surface Plots You define a surface by the z-coordinates of points above a grid in the x-y plane, using straight lines to connect adjacent points. The mesh and surf plotting functions display surfaces in three dimensions. mesh produces wireframe surfaces that color only the lines connecting the defining points. surf displays both the connecting lines and the faces of the surface in color.
5
Creating mesh and surface plots
Visualizing Functions of Two Variables meshgrid [X,Y] = meshgrid(x,y) [X,Y] = meshgrid(x,y) transforms the domain specified by vectors x and y into arrays X and Y, which can be used to evaluate functions of two variables and three-dimensional mesh/surface plots. The rows of the output array X are copies of the vector x; columns of the output array Y are copies of the vector y.
6
Creating mesh and surface plots
Visualizing Functions of Two Variables meshgrid [X,Y] = meshgrid(1:3,10:14) X = Y =
7
Creating mesh and surface plots
Visualizing Functions of Two Variables To display a function of two variables, z = f (x,y), Generate X and Y matrices consisting of repeated rows and columns, respectively, over the domain of the function. Use X and Y to evaluate and graph the function. The meshgrid function transforms the domain specified by a single vector or two vectors x and y into matrices X and Y for use in evaluating functions of two variables. The rows of X are copies of the vector x and the columns of Y are copies of the vector y
8
Creating mesh and surface plots
Example — Graphing the sinc Function This example evaluates and graphs the two-dimensional sinc function, sin(r)/r, between the x and y directions. R is the distance from the origin, which is at the center of the matrix. Adding eps (a MATLAB command that returns a small floating-point number) avoids the indeterminate 0/0 at the origin [X,Y] = (-8:.5:8); R = sqrt(X.^2 meshgrid+ Y.^2) + eps; Z = sin(R)./R; mesh(X,Y,Z,'EdgeColor','black')
9
Creating mesh and surface plots
Example — Graphing the sinc Function
10
Creating mesh and surface plots
Example — Colored Surface Plots A surface plot is similar to a mesh plot except that the rectangular faces of the surface are colored. The color of each face is determined by the values of Z and the colormap (a colormap is an ordered list of colors). These statements graph the sinc function as a surface plot, specify a colormap, and add a color bar to show the mapping of data to color surf(X,Y,Z) colormap hsv colorbar
11
Creating mesh and surface plots
Example — Colored Surface Plots
12
Creating mesh and surface plots
Manipulating the Surface The figure toolbar and the camera toolbar provide ways to explore 3-D graphics interactively. Display the camera toolbar by selecting Camera Toolbar from the figure View menu. The following picture shows both toolbars with the Rotate 3D tool selected.
13
Creating mesh and surface plots
Manipulating the Surface
14
Homework Plot a circle. It’s not immediately obvious how to plot a circle in Matlab. Write the function [x,y]=getCircle(center,r) to get the x and y coordinates of a circle. The circle should be centered at center (2- element vector containing the x and y values of the center) and have radius r. Return x and y such that plot(x,y) will plot the circle. Recall that for a circle at the origin (0,0), the following is true: , x = sin(t) y =cos(t) t= [0, 2π]
15
Homework Write a script called concentric.m. In this script, open a new figure and plot five circles, all centered at the origin and with increasing radii. Set the line width for each circle to something thick (at least 2 points), and use the colors from a 5-color jet colormap (jet). The property names for line width and color are ‘LineWidth’ and ‘Color’, respectively. Other useful function calls are hold on and axis equal. It should look something like this :
16
Homework Make a script called olympic.m. This script should use your getCircle function to draw the Olympic logo, as shown below. Don’t worry about making the circles overlap in the same way as the official logo (it’s possible but is too complicated for now). Also, when specifying colors, you can use the same color codes as when plotting lines
17
End of lecture 3 Thank you for listening See you next week
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.