Numerical Analysis Using MATLAB and Spreadsheets, Second Edition 1-11
Orchard Publications
Using MATLAB to Make Plots
To return to the command window, we press any key, or from the Window pull-down menu, we
select MATLAB Command Window. To see the graph again, we click on the Window pull-down
menu, and we select Figure.
We can make the above, or any plot, more presentable with the following commands:
grid on: This command adds grid lines to the plot. The grid off command removes the grid. The
command
grid toggles them, that is, changes from off to on or vice versa. The default
*
is off.
box off: This command removes the box (the solid lines which enclose the plot), and box on
restores the box. The command box toggles them. The default is on.
title(‘string’): This command adds a line of the text string (label) at the top of the plot.
xlabel(‘string’) and ylabel(‘string’) are used to label the - and -axis respectively.
The amplitude frequency response is usually represented with the -axis in a logarithmic scale.
We can use the
semilogx(x,y) command that is similar to the plot(x,y) command, except that
the -axis is represented as a log scale, and the -axis as a linear scale. Likewise, the semil-
ogy(x,y)
command is similar to the plot(x,y) command, except that the -axis is represented as a
log scale, and the -axis as a linear scale. The loglog(x,y) command uses logarithmic scales for
both axes.
Throughout this text, it will be understood that log is the common (base 10) logarithm, and ln is
the natural (base e) logarithm. We must remember, however, the function log(x) in MATLAB is
the natural logarithm, whereas the common logarithm is expressed as
log10(x). Likewise, the log-
arithm to the base 2 is expressed as
log2(x).
Let us now redraw the plot with the above options, by adding the following statements:
semilogx(w,z); grid; % Replaces the plot(w,z) command
title('Magnitude of Impedance vs. Radian Frequency');
xlabel('w in rads/sec'); ylabel('|Z| in Ohms')
After execution of these commands, our plot is as shown in Figure 1.3.
If the -axis represents power, voltage, or current, the -axis of the frequency response is more
often shown in a logarithmic scale, and the -axis in dB (decibels) scale. A review of the decibel
unit follows.
The ratio of any two values of the same quantity (power, voltage, or current) can be expressed in
decibels (dB). Thus, we say that an amplifier has power gain, or a transmission line has a
power loss of (or gain ). If the gain (or loss) is the output is equal to the input.
* Default is a particular value for a variable or condition that is assigned automatically by an operating system, and remains
in effect unless canceled or overridden by the operator.
xy
x
xy
y
x
yx
y
10 dB
7 dB 7– dB 0 dB