O'Reilly logo

Learning to Program with MATLAB: Building GUI Tools by Craig S. Lent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

images

3.1   The plot command

3.2   Tabulating and plotting a simple function

3.3   Bar graphs and histograms

3.4   Drawing several plots on one graph

3.5   Adding lines and text

MATLAB is exceptional among programming languages for the power of its built-in graphics capabilities. This chapter will introduce the fundamentals of making two-dimensional linear plots.

In MATLAB, a basic x-y plot is constructed from two MATLAB vectors that define a set of points in the plane. The points are often connected by line segments so that, if the density of points is high, a smooth curve results. Separate MATLAB commands control the axis scaling, color of the lines, labeling of the axes, appearance of grid lines, and other aspects of the plot.

One of the most common graphics tasks is tabulating and plotting a mathematical function. One can use the linspace command to create a regularly spaced array of points representing the independent variable, and then use MATLAB vector math to create a tabulation of the values of a specific function, the dependent variable, at those points. The plot command, and associated formatting commands, can then be used to make a graph of the function. For some kinds of data, bar plots or histogram plots are a more natural way to represent the information graphically.

After mastering the material in this chapter you should be able to write programs that:

  • Create x-y plots ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required