holds the current plot and all axis properties so that
subsequent graphing commands add to the existing graph.
HOLD OFF returns to the default mode whereby PLOT commands erase
the previous plots and reset all axis properties before drawing
HOLD, by itself, toggles the hold state.
HOLD does not affect axis autoranging properties.
sets the NextPlot property of the current figure and
axes to "add".
HOLD OFF sets the NextPlot property of the current axes to
See also ISHOLD, NEWPLOT, FIGURE, AXES.
Create axes in tiled positions.
SUBPLOT(m,n,p), or SUBPLOT(mnp), breaks the Figure window into
an m-by-n matrix of small axes, selects the p-th axes for
for the current plot, and returns the axis handle. The axes
are counted along the top row of the Figure window, then the
second row, etc. For example,
plots income on the top half of the window and outgo on the
SUBPLOT(m,n,p), if the axis already exists, makes it current.
SUBPLOT(H), where H is an axis handle, is another way of making
an axis current for subsequent plotting commands.
SUBPLOT('position',[left bottom width height]) creates an
axis at the specified position in normalized coordinates (in
in the range from 0.0 to 1.0).
If a SUBPLOT specification causes a new axis to overlap an
existing axis, the existing axis is deleted. For example,
the statement SUBPLOT(1,1,1) deletes all existing smaller
axes in the Figure window and creates a new full-figure axis.
lines and points in 3-D space.
PLOT3() is a three-dimensional analogue of PLOT().
PLOT3(x,y,z), where x, y and z are three vectors of the same length,
plots a line in 3-space through the points whose coordinates are the
elements of x, y and z.
PLOT3(X,Y,Z), where X, Y and Z are three matrices of the same size,
plots several lines obtained from the columns of X, Y and Z.
Various line types, plot symbols and colors may be obtained with
PLOT3(X,Y,Z,s) where s is a 1, 2 or 3 character string made from
the characters listed under the PLOT command.
PLOT3(x1,y1,z1,s1,x2,y2,z2,s2,x3,y3,z3,s3,...) combines the plots
defined by the (x,y,z,s) fourtuples, where the x's, y's and z's are
vectors or matrices and the s's are strings.
Example: A helix:
t = 0:pi/50:10*pi;
PLOT3 returns a column vector of handles to LINE objects, one
handle per line. The X,Y,Z triples, or X,Y,Z,S quads, can be
followed by parameter/value pairs to specify additional
properties of the lines.
See also PLOT, LINE, AXIS, VIEW, MESH, SURF.
X and Y arrays for 3-D plots.
[X,Y] = MESHGRID(x,y) transforms the domain specified by vectors
x and y into arrays X and Y that can be used for the evaluation
of functions of two variables and 3-D surface plots.
The rows of the output array X are copies of the vector x and
the columns of the output array Y are copies of the vector y.
[X,Y] = MESHGRID(x) is an abbreviation for [X,Y] = MESHGRID(x,x).
[X,Y,Z] = MESHGRID(x,y,z) produces 3-D arrays that can be used to
evaluate functions of three variables and 3-D volumetric plots.
For example, to evaluate the function x*exp(-x^2-y^2) over the
range -2 < x < 2, -2 < y < 2,
[X,Y] = meshgrid(-2:.2:2, -2:.2:2);
Z = X .* exp(-X.^2 - Y.^2);
MESHGRID is like NDGRID except that the order of the first two input
and output arguments are switched (i.e., [X,Y,Z] = MESHGRID(x,y,z)
produces the same result as [Y,X,Z] = NDGRID(y,x,z)). Because of
this, MESHGRID is better suited to problems in cartesian space,
while NDGRID is better suited to N-D problems that aren't spatially
based. MESHGRID is also limited to 2-D or 3-D.
See also SURF, SLICE, NDGRID.
MESH(X,Y,Z,C) plots the colored parametric mesh defined by
four matrix arguments. The view point is specified by VIEW.
The axis labels are determined by the range of X, Y and Z,
or by the current setting of AXIS. The color scaling is determined
by the range of C, or by the current setting of CAXIS. The scaled
color values are used as indices into the current COLORMAP.
MESH(X,Y,Z) uses C = Z, so color is proportional to mesh height.
MESH(x,y,Z) and MESH(x,y,Z,C), with two vector arguments replacing
the first two matrix arguments, must have length(x) = n and
length(y) = m where [m,n] = size(Z). In this case, the vertices
of the mesh lines are the triples (x(j), y(i), Z(i,j)).
Note that x corresponds to the columns of Z and y corresponds to
MESH(Z) and MESH(Z,C) use x = 1:n and y = 1:m. In this case,
the height, Z, is a single-valued function, defined over a
geometrically rectangular grid.
MESH returns a handle to a SURFACE object.
AXIS, CAXIS, COLORMAP, HOLD, SHADING and VIEW set figure, axes, and
surface properties which affect the display of the mesh.
See also SURF, MESHC, MESHZ, WATERFALL.
ABS(X) is the absolute value of the elements of X. When
X is complex, ABS(X) is the complex modulus (magnitude) of
the elements of X.
See also SIGN, ANGLE, UNWRAP.
commands in M-files.
ECHO ON turns on echoing of commands inside Script-files.
ECHO OFF turns off echoing.
ECHO file ON where 'file' is a function name causes the
named Function-file to be echoed when it is used.
ECHO file OFF turns it off.
ECHO file toggles it.
ECHO ON ALL turns on the echoing of commands inside any
Function-files that are currently in memory (i.e., the
functions returned by INMEM).
ECHO OFF ALL turns them all off.
See also FUNCTION, SCRIPT.
CLF deletes all children of the current figure with visible handles.
CLF RESET deletes children with visible handles and also resets
all figure properties, except Position and Units, to their default
See also CLA, RESET, HOLD.
axis scaling and appearance.
AXIS([XMIN XMAX YMIN YMAX]) sets scaling for the x- and y-axes
on the current plot.
AXIS([XMIN XMAX YMIN YMAX ZMIN ZMAX]) sets the scaling for the
x-, y- and z-axes on the current 3-D plot.
V = AXIS returns a row vector containing the scaling for the
current plot. If the current view is 2-D, V has four
components; if it is 3-D, V has six components.
AXIS AUTO returns the axis scaling to its default, automatic
mode where, for each dimension, 'nice' limits are chosen based
on the extents of all line, surface, patch, and image children.
AXIS MANUAL freezes the scaling at the current limits, so that if
HOLD is turned on, subsequent plots will use the same limits.
AXIS TIGHT sets the axis limits to the range of the data.
AXIS FILL sets the axis limits and PlotBoxAspectRatio so that
the axis fills the position rectangle. This option only has
an effect if PlotBoxAspectRatioMode or DataAspectRatioMode are
AXIS IJ puts MATLAB into its "matrix" axes mode. The coordinate
system origin is at the upper left corner. The i axis is
vertical and is numbered from top to bottom. The j axis is
horizontal and is numbered from left to right.
AXIS XY puts MATLAB into its default "Cartesian" axes mode. The
coordinate system origin is at the lower left corner. The x
axis is horizontal and is numbered from left to right. The y
axis is vertical and is numbered from bottom to top.
AXIS EQUAL sets the aspect ratio so that equal tick mark
increments on the x-,y- and z-axis are equal in size. This
makes SPHERE(25) look like a sphere, instead of an ellipsoid.
AXIS IMAGE is the same as AXIS EQUAL except that the plot
box fits tightly around the data.
AXIS SQUARE makes the current axis box square in size.
AXIS NORMAL restores the current axis box to full size and
removes any restrictions on the scaling of the units.
This undoes the effects of AXIS SQUARE and AXIS EQUAL.
AXIS OFF turns off all axis labeling, tick marks and background.
AXIS ON turns axis labeling, tick marks and background back on.
See also AXES.
EXP(X) is the exponential of the elements of X, e to the X.
For complex Z=X+i*Y, EXP(Z) = EXP(X)*(COS(Y)+i*SIN(Y)).
See also LOG, LOG10, EXPM, EXPINT.
Invoke keyboard from M-file.
KEYBOARD, when placed in an M-file, stops execution of the file
and gives control to the user's keyboard. The special status is
indicated by a K appearing before the prompt. Variables may be
examined or changed - all MATLAB commands are valid. The keyboard
mode is terminated by executing the command RETURN (i.e. typing
the six letters R-E-T-U-R-N and pressing the return key). Control
returns to the invoking M-file.
The keyboard mode is useful for debugging your M-files.
See also DBSTOP, RETURN, INPUT.
ZOOM Zoom in
and out on a 2-D plot.
ZOOM with no arguments toggles the zoom state.
ZOOM(FACTOR) zooms the current axis by FACTOR.
Note that this does not affect the zoom state.
ZOOM ON turns zoom on for the current figure.
ZOOM OFF turns zoom off in the current figure.
ZOOM OUT returns the plot to its initial (full) zoom.
ZOOM XON or ZOOM YON turns zoom on for the x or y axis only.
ZOOM RESET clears the zoom out point.
When zoom is on, click the left mouse button to zoom in on the
point under the mouse. Click the right mouse button to zoom out
(shift-click on the Macintosh). Each time you click, the axes
limits will be changed by a factor of 2 (in or out). You can also
click and drag to zoom into an area. Double clicking zooms out to
the point at which zoom was first turned on for this figure. Note
that turning zoom on, then off does not reset the zoom point.
This may be done explicitly with ZOOM RESET.
ZOOM(FIG,OPTION) applies the zoom command to the figure specified
by FIG. OPTION can be any of the above arguments.
Create figure window.
FIGURE, by itself, creates a new figure window, and returns
FIGURE(H) makes H the current figure, forces it to become visible,
and raises it above all other figures on the screen. If Figure H
does not exist, and H is an integer, a new figure is created with
GCF returns the handle to the current figure.
Execute GET(H) to see a list of figure properties and
their current values. Execute SET(H) to see a list of figure
properties and their possible values.
See also SUBPLOT, AXES, GCF, CLF.
CLOSE(H) closes the window with handle H.
CLOSE, by itself, closes the current figure window.
CLOSE('name') closes the named window.
CLOSE ALL closes all the open figure windows.
CLOSE ALL HIDDEN closes hidden windows as well.
STATUS = CLOSE(...) returns 1 if the specified windows were closed
and 0 otherwise.
See also DELETE.
TEXT(X,Y,'string') adds the text in the quotes to location (X,Y)
on the current axes, where (X,Y) is in units from the current
plot. If X and Y are vectors, TEXT writes the text at all locations
given. If 'string' is an array the same number of rows as the
length of X and Y, TEXT marks each point with the corresponding row
of the 'string' array.
TEXT(X,Y,Z,'string') adds text in 3-D coordinates.
TEXT returns a column vector of handles to TEXT objects, one
handle per text object. TEXT objects are children of AXES objects.
The X,Y pair (X,Y,Z triple for 3-D) can be followed by
parameter/value pairs to specify additional properties of the text.
The X,Y pair (X,Y,Z triple for 3-D) can be omitted entirely, and
all properties specified using parameter/value pairs.
Execute GET(H), where H is a text handle, to see a list of text
object properties and their current values. Execute SET(H) to see a
list of text object properties and legal property values.
See also XLABEL, YLABEL, ZLABEL, TITLE, GTEXT, LINE, PATCH.
Log-log scale plot.
LOGLOG(...) is the same as PLOT(...), except logarithmic
scales are used for both the X- and Y- axes.
See also PLOT.
Semi-log scale plot.
SEMILOGX(...) is the same as PLOT(...), except a
logarithmic (base 10) scale is used for the X-axis.
See also PLOT.
Semi-log scale plot.
SEMILOGY(...) is the same as PLOT(...), except a
logarithmic (base 10) scale is used for the Y-axis.
See also PLOT.
For vectors, PROD(X) is the product of the elements of X. For
matrices, PROD(X) is a row vector with the product over each
column. For N-D arrays, PROD(X) operates on the first
PROD(X,DIM) works along the dimension DIM.
Example: If X = [0 1 2
3 4 5]
then prod(X,1) is [0 4 10] and prod(X,2) is [ 0
See also SUM, CUMPROD, DIFF.
Length of vector.
LENGTH(X) returns the length of vector X. It is equivalent
to MAX(SIZE(X)) for non-empty arrays and 0 for empty ones.
SIZE Size of
D = SIZE(X), for M-by-N matrix X, returns the two-element
row vector D = [M, N] containing the number of rows and columns
in the matrix. For N-D arrays, SIZE(X) returns a 1-by-N
vector of dimension lengths. Trailing singleton dimensions
[M,N] = SIZE(X) returns the number of rows and columns in
separate output variables. [M1,M2,M3,...,MN] = SIZE(X)
returns the length of the first N dimensions of X.
M = SIZE(X,DIM) returns the length of the dimension specified
by the scalar DIM. For example, SIZE(X,1) returns the number
See also LENGTH, NDIMS.
DET(X) is the determinant of the square matrix X.
Use COND instead of DET to test for matrix singularity.
See also COND.
\ Backslash or left division.
A\B is the matrix division of A into B, which is roughly the
same as INV(A)*B , except it is computed in a different way.
If A is an N-by-N matrix and B is a column vector with N
components, or a matrix with several such columns, then
X = A\B is the solution to the equation A*X = B computed by
Gaussian elimination. A warning message is printed if A is
badly scaled or nearly singular. A\EYE(SIZE(A)) produces the
inverse of A.
If A is an M-by-N matrix with M < or > N and B is a column
vector with M components, or a matrix with several such columns,
then X = A\B is the solution in the least squares sense to the
under- or overdetermined system of equations A*X = B. The
effective rank, K, of A is determined from the QR decomposition
with pivoting. A solution X is computed which has at most K
nonzero components per column. If K < N this will usually not
be the same solution as PINV(A)*B. A\EYE(SIZE(A)) produces a
generalized inverse of A.
/ Slash or right division.
B/A is the matrix division of A into B, which is roughly the
same as B*INV(A) , except it is computed in a different way.
More precisely, B/A = (A'\B')'. See \.
./ Array right division.
B./A denotes element-by-element division. A and B
must have the same dimensions unless one is a scalar.
A scalar can be divided with anything.
.\ Array left division.
A.\B. denotes element-by-element division. A and B
must have the same dimensions unless one is a scalar.
A scalar can be divided with anything.
EYE(N) is the N-by-N identity matrix.
EYE(M,N) or EYE([M,N]) is an M-by-N matrix with 1's on
the diagonal and zeros elsewhere.
EYE(SIZE(A)) is the same size as A.
See also ONES, ZEROS, RAND, RANDN.
Diagonal matrices and diagonals of a matrix.
DIAG(V,K) when V is a vector with N components is a square matrix
of order N+ABS(K) with the elements of V on the K-th diagonal. K = 0
is the main diagonal, K > 0 is above the main diagonal and K < 0
is below the main diagonal.
DIAG(V) is the same as DIAG(V,0) and puts V on the main diagonal.
DIAG(X,K) when X is a matrix is a column vector formed from
the elements of the K-th diagonal of X.
DIAG(X) is the main diagonal of X. DIAG(DIAG(X)) is a diagonal matrix.
m = 5;
diag(-m:m) + diag(ones(2*m,1),1) + diag(ones(2*m,1),-1)
produces a tridiagonal matrix of order 2*m+1.
See also SPDIAGS, TRIU, TRIL.
INV(X) is the inverse of the square matrix X.
A warning message is printed if X is badly scaled or
See also SLASH, PINV, COND, CONDEST, NNLS, LSCOV.