Basic 2-D Plots: X Values and y Values Are Vectors Containing The X-And Y-Coordinates of Points On The Graph
Basic 2-D Plots: X Values and y Values Are Vectors Containing The X-And Y-Coordinates of Points On The Graph
MATLAB has many commands that can be used to create basic 2-D plots, overlay plots,
specialized 2-D plots,
3-D plots, mesh and surface plots.
The style option in the plot command is a character string that consists of 1, 2 or 3 characters that
specify the color and/or the line style. The different color, line-style and marker-style options are
summarized in Table 1.
Function Description
area Creates a filled area plot.
bar Creates a bar graph.
barh Creates a horizontal bar graph.
comet Makes an animated 2-D plot.
compass Creates arrow graph for complex numbers.
contour Makes contour plots.
contourf Makes filled contour plots.
errorbar Plots a graph and puts error bars.
feather Makes a feather plot.
fill Draws filled polygons of specified color.
fplot Plots a function of a single variable.
hist Makes histograms.
loglog Creates plot with log scale on both x and y axes.
pareto Makes pareto plots.
pcolor Makes pseudo color plot of matrix.
pie Creates a pie chart.
plotyy Makes a double y-axis plot.
plotmatrix Makes a scatter plot of a matrix.
polar Plots curves in polar coordinates.
quiver Plots vector fields.
rose Makes angled histograms.
scatter Creates a scatter plot.
semilogx Makes semilog plot with log scale on the x-axis.
semilogy Makes semilog plot with log scale on the y-axis.
stairs Plots a stair graph.
stem Plots a stem graph.
Overlay plots
There are three ways of generating overlay plots in MATLAB. They are:
(a) Plot command.
(b) Hold command.
(c) Line command.
(a) Plot command
Example E1.5 (a) shows the use of plot command used with matrix argument, each column of
the second argument matrix plotted against the corresponding column of the first argument
matrix.
(b) Hold command
Invoking hold on at any point during a session freezes the current plot in the graphics window.
All the next plots generated by the plot command are added to the exiting plot. See Example
E1.5(a).
(c) Line command
The line command takes a pair of vectors (or a triplet in 3-D) followed by a parameter
name/parameter value pairs as argument. For instance, the command: line (x data, y data,
parameter name, parameter value) adds lines to the existing axes. See Example E1.5 (a).
3-D Plots
MATLAB provides various options for displaying three-dimensional data. They include line and
wire, surface, mesh plots, among many others. More information can be found in the Help
Window under Plotting and Data visualization. Table 3 lists commonly used functions.
meshgrid If x and y are two vectors containing a range of points for the evaluation of a
function,[X,Y] = meshgrid(x, y) returns two rectangular matrices containing
the x and y values at each point of a two-dimensional grid.
mesh(X,Y,z) If X and Y are rectangular arrays containing the values of the x and y
coordinates at each point of a rectangular grid , and if z is the value of a
function evaluated at each of these points, mesh(X,Y,z) will produce a three-
dimensional perspective graph of the points.The same results can be obtained
with mesh(x,y,z) can also be used.
meshc, meshz If the xy grid is rectangular, these two functions are merely variations of the
basic Plotting program mesh, and they operate in an identical fashion. meshc
will produce a corresponding contour plot drawn on the xy plane below the
three-dimensional figure, and meshz will add a vertical wall to the outside
features of the figures drawn by mesh.
Surfc This function is related to surf in the same way that meshc is related to
mesh.
Used to change the default coloring of a figure. See the MATLAB reference
Colormap manual or the help file.
Controls the type of color shading used in drawing figures. See the
Shading MATLAB reference manual or the help file.
View View (az,el) controls the perspective view of a three-dimensional plot. The
view of the figure is from angle “el” above the xy plane with the coordinate
axes (and the figure) rotated by an angle “az” in a clockwise direction about
the z axis. Both angles are in degrees. The default values are az = 37½º and
el = 30º.
Axis Determines or changes the scaling of a plot. If the coordinate axis limits of a
two-dimensional or three-dimensional graph are contained in the row vector
r = [xmin, xmax, ymin, ymax, zmin, zmax],
axis will return the values in this vector, and axis(r) can be used to alter
them. The coordinate axes can be turned on and off with axis(‘on’) and
axis(‘off’). A few other string constant inputs to axis and their effects are
given below:
axis(‘equal’) x and y scaling are forced to be the same.
axis(‘square’) The box formed by the axes is square.
axis(‘auto’) Restores the scaling to default settings.
axis(‘normal’) Restoring the scaling to full size, removing any effects of
square or equal settings.
axis(‘image’) Alters the aspect ratio and the scaling so the screen pixels are
square shaped rather than rectangular.
Contour
The use is contour(x,y,z). A default value of N = 10 contour lines will be
drawn. An optional fourth argument can be used to control the number of
contour lines that are drawn. contour(x,y,z,N), if N is a positive integer, will
draw N contour lines, and contour(x,y,z,V), if V is a vector containing
values in the range of z values, will draw contour lines at each value of z = V.
SYMBOLIC MATHEMATICS
SYMBOLIC MATHEMATICS
1.19.1 Symbolic Expressions
A symbolic expression is stored in MATLAB as a character string. A single quote marks are
used to define the symbolic expression.
Simplification
factor Factorization
simplify Simplification
Basic operations
Arithmetic operation
+ Addition
– Subtraction
* Multiplication
.* Array multiplication
/ Right division
./ Array right division
\ Left division
.\ Array left division
^ Matrix or scalar raised to a power
.^ Array raised to a power
‘ Complex conjugate transpose
.‘ Real transpose
Symbolic expressions
numden(S)
Returns two symbolic expressions that represent,
respectively, the numerator expression and the denominator
expression for the rational representation of S.