MATLAB(TM) Hypertext Reference, Copyright (c) 1995 Gerald Recktenwald, All rights reserved

Plotting with MATLAB

MATLAB is very useful for making scientific and engineering plots. You can create plots of known, analytical functions, you can plot data from other sources such as experimental measurements, you can analyze data, perhaps by fitting it to a curve, and then plot a comparison. MATLAB also has powerful built-in routines for drawing contour and three-dimensional surface plots z = f(x,y) data.

MATLAB plotting commands are best illustrated by example. I have tried to make the examples compact, while avoiding the trivial. The examples build on each other so it is advisable to at least skim through the presenation in order. Jumping from link to link will probably be more effective after you get a feel for the basic plotting commands and the organization of these web pages.

To keep the network response relatively quick, I organized the plotting information into several separate web pages. This page (the one you're reading now) serves as an introduction and as an index. Whenever you click the ``Section Outline'' button at the bottom of one subsidiary plotting pages you will be brought back to this page.

I've created one example to demonstrate each of the major plotting features. Both the plotting commands and the MATLAB output are shown. The examples are available as script files that are linked to these pages. Using these links you can easily download the example scripts to your computer. If you are not familiar with Web browsers you may want to refer to a brief set of instructions for help in downloading the scripts.

Loading your own data into MATLAB can sometimes be frustrating. I've presented a detailed discussion how to do this in two ways. One way is to use the MATLAB load command, which requires that your data be organized into columns with no labeling text. Another way involves a custom MATLAB function (available for downloading) that can strip heading text and read column labels from a plain text file.

MATLAB plot commands take vectors and matrices as input so you should be familiar with manipulating these variable types. Refer to the vectors and matrices sections for review. You should also know how to use colon notation to refer to parts of matrices and vectors. And finally, since script files are used to automate the process of creating plots you may want to skim ahead to the section on scripts.

Few things are more frustrating (to me at least) than having a plot of valuable data that has no labels. When I grade homework or reports I ignore all plots that are not properly labelled. I figure that if the author of the report did not bother to label the plot, the data must not be very important. It's not my job to try to read the mind of the person writing the report.

The following examples show how easy it is to not only create plots, but label them as well.

Here's the Outline of the Plotting Section

[Preceding Section] [Master Outline] [Section Outline] [Next Section]