Creating Multiple Plots Matlab

If you are working in an M-file when you request a plot, and then you continue with more computations, MATLAB ® will generate and display the graphics window and then return immediately to execute the rest of the commands in the program. If you request a second plot, the graph you created will be overwritten. There are two possible solutions to this problem: Use the pause command to temporarily halt the

execution of your M-file program so that you can examine the fi gure, or create a second figure, using the figure function. The pause command stops the program execution until any key is pressed. If you want to pause for a specified number of seconds, use the pause(n) command, which will cause execution to pause for n seconds before continuing.

The figure command allows you to open a new figure window. The next time you request a plot, it will be displayed in this new window. For example, figure(2)opens a window named “Figure 2,” which then becomes the window used for subse-quent plotting. Executing figure without an input parameter causes a new window to open, numbered consecutively one up from the current window. For example, if the current figure window is named “Figure 2,” executing figure will cause “Figure 3” to open. The commands used to create a simple plot are summarized in Table 5.1 .

Titles, Labels, and Grids Matlab

Good engineering practice requires that we include axis labels and a title in our plot. The following commands add a title, x – and y -axis labels, and a background grid:


xlabel(‘Time, sec’)

ylabel(‘Distance, ft’)

grid on


These commands generate the plot in Figure 5.2 . As with any MATLAB ®com-mands, they could also be combined onto one or two lines, separated by commas:

plot(x,y) , title(‘Laboratory Experiment 1’)

xlabel(‘Time, sec’ ), ylabel(‘Distance, ft’), grid

Simple x–y Plots


Once vectors of x -values and y -values have been defi ned, MATLAB makes it easy to  create plots. Suppose a set of time versus distance data were obtained through measurement.

We can store the time values in a vector called x (the user can define any con-venient name) and the distance values in a vector called y :
x = [0:2:18];
y = [0, 0.33, 4.13, 6.29, 6.85, 11.19, 13.19, 13.96, 16.33,
To plot these points, use the plot command, with x and y as arguments:

x,y plot matlab

A graphics window automatically opens, which MATLAB  calls Figure 1. The resulting plot is shown in Figure 5.1 . (Slight variations in scaling of the plot may  occur, depending on the size of the graphics window.)

matlab plot imagen