Chapter 4 Review - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Chapter 4 Review

Description:

Large tables and reams of data are difficult to interpret. ... calculations or experimental measurements, we have amassed data where y = f(x) ... – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 19
Provided by: Mixs
Category:

less

Transcript and Presenter's Notes

Title: Chapter 4 Review


1
Chapter 4 Review
  • Introduction to MATLAB 7
  • Engineering 161

2
Plotting
  • Large tables and reams of data are difficult to
    interpret.
  • Graphing techniques facilitate seeing trends,
    picking out highs and lows, and serve as a quick
    check on ones calculations.
  • Most common plot is the x-y plot, i.e., a two
    dimensional plot.
  • MATLAB is rich in both 2 and 3 dimensional
    graphing capabilities. We are going to study 2
    dimensional plotting.

3
Plotting II
  • When we complete the material in Chapter 4, we
    will be able to
  • Create and label 2-dimensional plots.
  • Adjust the appearance of your plots.
  • Use our plots to interpret our results.
  • Have a basis for studying more complex MATLAB
    graphical capabilities.

4
Basic Plotting Concepts
  • In general, through calculations or experimental
    measurements, we have amassed data where y
    f(x).
  • We call x the independent variable and y the
    dependent variable. x and y are usually n
    dimensional vectors.
  • Plotting is nothing more than a visual
    representation of the relationship between x and
    y.

5
Basic Plotting Concepts II
  • The basic MATLAB plotting command is plot (x
    , y)
  • The graph is generated in the MATLAB Graphics
    window and labeled as Figure 1 or 2, etc.
  • Simple MATLAB commands allow you to label the x
    and y axes, label your graph, label legends, and
    format the graph as you want.

6
Basic Plotting Concepts III
  • It is easy to plot multiple sets of data in a
    single graph,
  • And to generate multiple graphs in a single
    Graphics Window. MATLAB calls these sub-plots.

7
Plotting Functions
  • MATLAB supports a number of basic plotting
    functions in addition to the line chart. These
    include
  • Bar Charts (vertical and horizontal, 3
    dimensional)
  • Pie Charts (2 and 3 dimensional)
  • Histograms
  • Semilog plots
  • Loglog plots
  • Polar plots

8
Plotting Commands
  • The basic plotting command is plot (x , y) where
    x is the independent variable and y is the
    dependent variable.
  • plot (x, y1, x, y2) will plot two lines in the
    graph
  • For y y1y2, plot (x , Y) will generate the
    same plot as above. When the dependent variable
    is a matrix, MATLAB plots each row of Y vs x.
  • Another way to plot 2 lines on one graph is to
    use the hold on command
  • plot (x,y1)
  • hold on
  • plot (x,y2)
  • hold off
  • Normally when MATLAB executes a plot command it
    erases the current figure and then plots anew.
    The command hold on suppresses the erase.

9
Plotting Commands II
  • Labeling your graphs axes, and titling your chart
    is easy.
  • Use the xlabel ( . . . .) and the ylabel (
    . . . .) commands to label your axes
    appropriately. You must surround your labels in
    single quotes. Single quotes tell MATLAB that it
    is a character string.
  • Use the title ( . . . .) command to title the
    graph.
  • Use the legend (line1, line2, line3)
    command to identify a designator with each line
    on your graph. The order of the entries
    corresponds to the order that you plotted the
    lines.
  • Or use the Insert Tab on the Graphics Window
    toolbar to customize your graph. NOTE when you
    customize a graph interactively, i.e., using the
    Insert Tab, the next time you run the program,
    the customization is lost.

10
Plotting Commands III
  • To open multiple figures use the Figure (n)
    command, Figure 1 is the default window, but
    after using this window to plot in, enter the
    command Figure (2) to create a new graphics
    window. The next time you plot, the 2nd graphics
    window will be used thereby preserving the
    results graphed in Figure 1. Both windows can be
    viewed as wanted.
  • Dont forget when in need of information about
    the plot command, enter help plot in the
    Command Window for information.
  • Finally, the command plot (y) makes sense to
    MATLAB. Here MATLAB uses the indices of the
    vector y as the x values.

11
Line, Color and Mark Style
  • You can select line type, point type, and color
    for each of your plotted lines.
  • See page 107 of the text for a Table of the
    option codes to use.
  • For example, plot (x,y, og) will generate a
    dotted line, with a circle point type, and color
    green.
  • Enter 1, 2 or 3 option codes in any order
    surrounded by single quotes to define the style
    you want to use with your line graph. The option
    codes need to immediately follow the x,y pair
    where they specify the style.
  • When multiple lines are being plotted using a
    single plot command, follow each x,y pair with
    its option code in single quotes and separated by
    commas.
  • When no option codes are present, MATLAB uses its
    default code, solid black line with no point type.

12
Axes Scaling
  • Unless you choose to scale your axes, MATLAB will
    scale them automatically based upon the values in
    x and y. This is the easiest method.
  • But, you can scale your axes with the axis (v)
    command where v xmin, xmax, ymin, ymax, that
    is, v is a 4 element row vector provided by you
    with the min and max values for each axes.
  • The command axis without the argument v freezes
    the current axes scale for subsequent plots.
    Enter axis again to unfreeze.

13
Axes Scaling II
  • Sometimes you will want to have two different
    vertical axes scaling, one on the left hand side
    of the graph and the other on the right hand
    side. To do this
  • Use the plotyy (x, y1, x, y2) command to force
    MATLAB to scale the vertical axes independently
    for the two lines in your chart.
  • Then use the Insert Tab in the graphics window to
    label the right hand vertical axis.
  • The chart title, and x and left hand y axes
    labels can be added using the title, xlabel and
    ylabel commands. Only the right hand label needs
    to be added using the Insert Tab.

14
Subplots
  • The subplot command allows you to split the
    graphics window into a number of sub-windows.
  • You can choose two sub-windows arranged
    horizontally or vertically, or
  • You can choose an array of sub-windows, say two
    rows with two columns or 4 subplots displayed at
    one time.
  • More than 4 isnt too practical. Things get too
    small.

15
Subplots II
  • The subplot command is specified in the following
    manner,
  • subplot (m,n,p) where m, n, and p are integers
    m and n specify the size of the array of subplots
    and p specifies which subplot is being
    referenced. Subplots are numbered from left to
    right, top to bottom.
  • subplot (2,2,3) would specify a 2 by 2 array of
    subplots with the 3 indicating the lower left
    hand plot in the array.
  • To use this feature, you will do the following
  • gtgt subplot (2,1,1) The subplot command
    proceeds
  • gtgt plot (x,y) the plot command.
  • Here two subplots are specified, one over the
    other, the plot takes place in the upper chart.

16
Subplots III
  • Chart titling, axes labeling, etc., following the
    plot command will refer to the last subplot
    indicated. Any additional plot commands will
    also refer to the last subplot indicated. To
    select a new sub-window to plot in, you have to
    select that sub-window with a subplot command
    before you use the plot (x,y) command. You can
    graph multiple x,y pairs in each subplot, select
    the style, add legends, etc., just as you have
    learned how to do with a single graph.

17
Plotting from the Workspace Window
  • MATLAB 7 allows you to create plots from the
    Workspace window. This lets you view
    intermediate results or any variable in the
    Workspace window.
  • In the Workspace window, select the variable you
    want to plot. If more than one, hold down the
    Ctrl key and select the additional ones that you
    want plotted.
  • Next click on the plotting icon, the squiggly
    line in the the Workspace toolbar. MATLAB
    selects what it thinks would be good plotting
    options based upon the data.
  • Select your graph type and the graph is
    generated.
  • Use More plots to see a complete list of plot
    options.

18
Chapter 4 Assignments
  • Chapter 4 assignments let you practice plotting.
    They are,
  • 4.1, 4.2, 4.5, 4.7, 4.9a and 4.9b
Write a Comment
User Comments (0)
About PowerShow.com