ENGR 1181 MATLAB 13: 2D Plots 2
Preparation Material

ENGR 1181 | MATLAB 13: 2D Plots 2Preparation Material

Learning Objectives

  1. Create other 2D graphing options in MATLAB (e.g.,log, bar, subplot, fplot)
  2. Select the proper opportunities to utilize aforementioned 2D graphing options

Topics

Students will read Chapter 5 of the MATLAB book before coming to class. This preparation material is provided to supplement this reading.

Students will learn more advanced techniques and syntax for creating and formatting two-dimensional (2D) plots in MATALB. This material contains the following:

  1. Organize Multiple Plots on the Same Page
  2. Logarithmic Plots
  3. Plots with Special Formats
  4. The fplot() Command

1. Organize Multiple Plots on the Same Page

Multiple plots on one page can be created with the subplot() command.

This command creates mxn plots in the Figure Window. The plots are arranged in m rows and ncolumns. The variable p defines which plot is active. The plots are numbered from 1 to mxn. The upper left plot is 1 and the lower right plot is mxn. The numbers increase from left to right within a row, from the first row to the last.

For example, to create 6 plots arrange in 3 rows and 2 columns, enter the following:


The input subplot(3,2,p) will create multiple plots on a the same page with the following structure:

Example using fplot() Command

The following fplot() output is a 2x3 layout. The script file of this figure is shown on the next page:

The following script files is used to execute the plots from the previous page:

2. Logarithmic Plots

The following commands are used to plot with logarithmic scales (axes):

Important Facts about Logarithmic Plots

Remember the following about logarithmic plots:

  1. Negative numbers cannot be plotted on log scales (because the log of a negative number is not defined).
  2. The number zero (0) cannot be plotted on a log scale.
  3. The tick-mark labels on a log scale are the actual values being plotted (they are not the logarithms of the numbers).
  4. Equal distances on a log scale correspond to multiplication by the same constant (as opposed to a linear scale, where equal distances correspond to the addition of the same constant).
  5. Tick marks are not evenly spaced.
Plotting with Linear and Log Scales

Plots can look very different based on scale of numbers, but also on the type of scale. The following shows the variation of graphs for the formula:

3. Plots with Special Formats

The following commands are used for plots with special geometry:

Below are examples of each of these type of plot formats:

4. The fplot() Command

The fplot() command can be used to plot a functionwith the form: y = f(x)

Remember the following about the fplot() command:

  • The function is typed in as a string.
  • The limits is a vector with the domain of x, and optionally with limits of the y axis:

[xmin,xmax] or [xmin,xmax,ymin,ymax]

  • Line specifiers can be added, just like with plot command
Plotting with the fplot() Command

For example, let’s say we want to plot the following equation and domain:

The MATLAB syntax would be the following equation and the output is below:

1