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: