If you can't read please download the document
Upload
june
View
20
Download
1
Embed Size (px)
DESCRIPTION
More stuff on plotting. Define x and y and call the plot function. Engineers always add …. Title title(‘y = cos(x)’) X axis label, complete with units xlabel(‘x-axis’) Y axis label, complete with units ylabel(‘y-axix’) Often it is useful to add a grid grid on. Single quotes are used. - PowerPoint PPT Presentation
Citation preview
CSCI6370: Topics in Computer Science Advanced Topics in Algorithms and Applications Fall Semester, 2002
More stuff on plotting1Define x and y and call the plot function
2Engineers always add Title title(y = cos(x))X axis label, complete with units xlabel(x-axis)Y axis label, complete with units ylabel(y-axix)Often it is useful to add a grid grid onSingle quotes are used.3Change the line type in a plotExampleplot(x, y, ':ok')strings are identified with single quotesthe : means use a dotted linethe o means use a circle to mark each pointthe letter k indicates that the graph should be drawn in black(b indicates blue)
4Available choicesTable 5. 2 Line, Mark and Color OptionsLine TypeIndicatorPoint TypeIndicatorColorIndicatorsolid-point.bluebdotted:circleogreengdash-dot-.x-markxredrdashed--plus+cyancstar*magentamsquaresyellowydiamonddblackktriangle downvtriangle up^triangle left
pentagramphexagramh5
specify the drawing parameters for each line after the ordered pairs that define the line6SubplotsThe subplot command allows you to subdivide the graphing window into a grid of m rows and n columnssubplot(m,n,p)rowscolumnslocation7subplot(2,2,1)2 rows2 columns1234
8
2 rows and 1 column9Other Types of 2-D PlotsPolar PlotsLogarithmic PlotsBar GraphsPie ChartsHistogramsX-Y graphs with 2 y axesFunction Plots10
Three Dimensional Plotting3D Line plots (i.e. plot3(x,y,z))Surface plots (i.e. mesh(z) and surf(z))Contour plots11
Mesh plotsmesh(z) plots out a 3D plot The z-axis are the values of zThe x-axis is each point corresponding to a columnThe y-axis is each point corresponding to a rowExample:
Z = [1 2 3; 4 5 6]mesh(Z)
12
Mesh plots continuedCan also do mesh(x,y,z) this allows the x and y axis to be something else other than the number of rows and columnsx and y need to have the same dimensions as z.If x and y are vectors, need to use meshgrid to make them a 2D matrix. 13
meshgrid exampleExample:
Z = [1 2 3; 4 5 6] %2x3 matrixx=[0:3:6] %number of columns is 3y=[0:6:6] %number of rows is 2[X,Y] = meshgrid(x,y) %new X and Y that are 2x3 matricesmesh(X,Y,Z)xlabel(X)ylabel(Y)zlabel(Z)14
meshgrid example outputZ =
1 2 3 4 5 6
x =
0 3 6
y =
0 6
X =
0 3 6 0 3 6
Y =
0 0 0 6 6 6
15
surf plotsA surf plot is basically the same as mesh plot except that surf plots give a color surface instead of a mesh
Ex: surf(X,Y,Z)16In-class assignmentProblems 4.6, 4.7, and 4.9 from the Matlab book17