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 ...

Get Learning to Program with MATLAB: Building GUI Tools now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.