This chapter presents the following content: Chapter 5 “plotting”, two dimensional plots, simple x-y plots, titles, labels and grids, multiple plots. | Lecture 23 Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots Plots with More than One Line A plot with more than one line can be created in several ways By default, the execution of a second plot statement will erase the first plot However, you can layer plots on top of one another by using the hold on command Execute the following statements to create a plot with both functions plotted on the same graph x = 0:pi/100:2*pi; y1 = cos(x*4); plot(x,y1) y2 = sin(x); hold on; plot(x, y2) The hold on command can be used to layer plots on same graph Continued . Semicolons are optional on both the plot statement and the hold on statement MATLAB will continue to layer the plots until the hold off command is executed: hold off Another way to create a graph with multiple lines is to request both lines in a single plot command MATLAB interprets the input to plot as alternating x and y vectors, as in plot(X1, Y1, X2, Y2) where the variables X1 | Lecture 23 Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots Plots with More than One Line A plot with more than one line can be created in several ways By default, the execution of a second plot statement will erase the first plot However, you can layer plots on top of one another by using the hold on command Execute the following statements to create a plot with both functions plotted on the same graph x = 0:pi/100:2*pi; y1 = cos(x*4); plot(x,y1) y2 = sin(x); hold on; plot(x, y2) The hold on command can be used to layer plots on same graph Continued . Semicolons are optional on both the plot statement and the hold on statement MATLAB will continue to layer the plots until the hold off command is executed: hold off Another way to create a graph with multiple lines is to request both lines in a single plot command MATLAB interprets the input to plot as alternating x and y vectors, as in plot(X1, Y1, X2, Y2) where the variables X1 , Y1 form an ordered set of values to be plotted and X2 , Y2 form a second ordered set of values. Continued . If the plot function is called with a single matrix argument, MATLAB draws a separate line for each column of the matrix The x -axis is labeled with the row index vector, 1: k , where k is the number of rows in the matrix. This produces an evenly spaced plot, sometimes called a line plot If plot is called with two arguments, one a vector and the other a matrix, MATLAB successively plots a line for each row in the matrix For example: we can combine y1 and y2 into a single matrix and plot against x : Y = [y1; y2]; plot(x,Y) This creates the same plot as previous figure, with each line a different color Continued . Here’s another more complicated example: X = 0:pi/100:2*pi; Y1 = cos(X)*2; Y2 = cos(X)*3; Y3 = cos(X)*4; Y4 = cos(X)*5; Z = [Y1; Y2; Y3; Y4]; plot(X, Y1, X, Y2, X, Y3, X, Y4) This code produces the same result as plot(X, Z) Multiple Plots on Same Graph Continued . A .