RAND
Uniformly distributed random numbers.
RAND(N) is an NbyN matrix with random entries, chosen from
a uniform distribution on the interval (0.0,1.0).
RAND(M,N) and RAND([M,N]) are MbyN matrices with random entries.
RAND(M,N,P,...) or RAND([M,N,P,...]) generate random arrays.
RAND with no arguments is a scalar whose value
changes each time it
is referenced. RAND(SIZE(A)) is the same size as A.
S = RAND('state') is a 35element vector
containing the current state
of the uniform generator. RAND('state',S) resets the state to S.
RAND('state',0) resets the generator to its initial state.
RAND('state',J), for integer J, resets the
generator to its Jth state.
RAND('state',sum(100*clock)) resets it to a
different state each time.
This generator can generate all the floating point numbers in the
closed interval [2^(53), 12^(53)]. Theoretically, it can generate
over 2^1492 values before repeating itself.
MATLAB Version 4.x used random number generators with a single seed.
RAND('seed',0) and RAND('seed',J) cause the
MATLAB 4 generator to be used.
RAND('seed') returns the current seed of the
MATLAB 4 uniform generator.
RAND('state',J) and RAND('state',S) cause
the MATLAB 5 generator to be used.
See also RANDN, SPRAND, SPRANDN, RANDPERM.
MEAN Average
or mean value.
For vectors, MEAN(X) is the mean value of the elements in X. For
matrices, MEAN(X) is a row vector containing the mean value of
each column. For ND arrays, MEAN(X) is the mean value of the
elements along the first nonsingleton dimension of X.
MEAN(X,DIM) takes the mean along the dimension DIM of X.
Example: If X = [0 1 2
3 4 5]
then mean(X,1) is [1.5 2.5 3.5] and mean(X,2) is [1
4]
See also MEDIAN, STD, MIN, MAX, COV.
MEDIAN
Median value.
For vectors, MEDIAN(X) is the median value of the elements in X.
For matrices, MEDIAN(X) is a row vector containing the median
value of each column. For ND arrays, MEDIAN(X) is the median
value of the elements along the first nonsingleton dimension
of X.
MEDIAN(X,DIM) takes the median along the dimension DIM of X.
Example: If X = [0 1 2
3 4 5]
then median(X,1) is [1.5 2.5 3.5] and median(X,2) is [1
4]
See also MEAN, STD, MIN, MAX, COV.
STD Standard
deviation.
For vectors, STD(X) returns the standard deviation. For matrices,
STD(X) is a row vector containing the standard deviation of each
column. For ND arrays, STD(X) is the standard deviation of the
elements along the first nonsingleton dimension of X.
STD(X) normalizes by (N1) where N is the sequence length. This
makes STD(X).^2 the best unbiased estimate of the variance if X
is a sample from a normal distribution.
STD(X,1) normalizes by N and produces the second moment of the
sample about its mean. STD(X,0) is the same as STD(X).
STD(X,FLAG,DIM) takes the standard deviation along the dimension
DIM of X. When FLAG=0 STD normalizes by (N1), otherwise STD
normalizes by N.
Example: If X = [4 2 1
9 5 7]
then std(X,0,1) is [ 3.5355 4.9497 4.2426] and std(X,0,2) is [3.0
2.0]
See also COV, MEAN, MEDIAN, CORRCOEF.
MIN Smallest
component.
For vectors, MIN(X) is the smallest element in X. For matrices,
MIN(X) is a row vector containing the minimum element from each
column. For ND arrays, MIN(X) operates along the first
nonsingleton dimension.
[Y,I] = MIN(X) returns the indices of the minimum values in vector I.
If the values along the first nonsingleton dimension contain more
than one minimal element, the index of the first one is returned.
MIN(X,Y) returns an array the same size as X and Y with the
smallest elements taken from X or Y. Either one can be a scalar.
[Y,I] = MIN(X,[],DIM) operates along the dimension DIM. Suppose
X=[2 8 4;7 3 9] then min(X,[],1) is [2 3 4] and min(X,[],2) is [2,3].
When complex, the magnitude MIN(ABS(X)) is used. NaN's are ignored
when computing the minimum.
Example: If X = [2 8 4 then min(X,[],1) is [2 3 4],
7 3 9]
min(X,[],2) is [2 and min(X,5) is [2 5 4
3], 5 3 5].
See also MAX, MEDIAN, MEAN, SORT.
MAX Largest
component.
For vectors, MAX(X) is the largest element in X. For matrices,
MAX(X) is a row vector containing the maximum element from each
column. For ND arrays, MAX(X) operates along the first
nonsingleton dimension.
[Y,I] = MAX(X) returns the indices of the maximum values in vector I.
If the values along the first nonsingleton dimension contain more
than one maximal element, the index of the first one is returned.
MAX(X,Y) returns an array the same size as X and Y with the
largest elements taken from X or Y. Either one can be a scalar.
[Y,I] = MAX(X,[],DIM) operates along the dimension DIM.
When complex, the magnitude MAX(ABS(X)) is used. NaN's are
ignored when computing the maximum.
Example: If X = [2 8 4 then max(X,[],1) is [7 8 9],
7 3 9]
max(X,[],2) is [8 and max(X,5) is [5 8 5
9], 7 5 9].
See also MIN, MEDIAN, MEAN, SORT.
SUM Sum of
elements.
For vectors, SUM(X) is the sum of the elements of X. For
matrices, SUM(X) is a row vector with the sum over each
column. For ND arrays, SUM(X) operates along the first
nonsingleton dimension.
SUM(X,DIM) sums along the dimension DIM.
Example: If X = [0 1 2
3 4 5]
then sum(X,1) is [3 5 7] and sum(X,2) is [ 3
12];
See also PROD, CUMSUM, DIFF.
Overloaded methods
help sym/sum.m
CUMSUM
Cumulative sum of elements.
For vectors, CUMSUM(X) is a vector containing the cumulative sum of
the elements of X. For matrices, CUMSUM(X) is a matrix the same size
as X containing the cumulative sums over each column. For ND
arrays, CUMSUM(X) operates along the first nonsingleton dimension.
CUMSUM(X,DIM) works along the dimension DIM.
Example: If X = [0 1 2
3 4 5]
then cumsum(X,1) is [0 1 2 and cumsum(X,2) is [0 1 3
3 5 7] 3 7 12]
See also CUMPROD, SUM, PROD.
HIST
Histogram.
N = HIST(Y) bins the elements of Y into 10 equally spaced containers
and returns the number of elements in each container. If Y is a
matrix, HIST works down the columns.
N = HIST(Y,M), where M is a scalar, uses M bins.
N = HIST(Y,X), where X is a vector, returns the distribution of Y
among bins with centers specified by X.
[N,X] = HIST(...) also returns the position of the bin centers in X.
HIST(...) without output arguments produces a histogram bar plot of
the results.
RANDN
Normally distributed random numbers.
RANDN(N) is an NbyN matrix with random entries, chosen from
a normal distribution with mean zero and variance one.
RANDN(M,N) and RANDN([M,N]) are MbyN matrices with random entries.
RANDN(M,N,P,...) or RANDN([M,N,P...]) generate random arrays.
RANDN with no arguments is a scalar whose value changes each time it
is referenced. RANDN(SIZE(A)) is the same size as A.
S = RANDN('state') is a 2element vector containing the current state
of the normal generator. RANDN('state',S) resets the state to S.
RANDN('state',0) resets the generator to its initial state.
RANDN('state',J), for integer J, resets the generator to its Jth state.
RANDN('state',sum(100*clock)) resets it to a different state each time.
MATLAB Version 4.x used random number generators with a single seed.
RANDN('seed',0) and RANDN('seed',J) cause the MATLAB 4 generator
to be used.
RANDN('seed') returns the current seed of the MATLAB 4 normal generator.
RANDN('state',J) and RANDN('state',S) cause the MATLAB 5 generator
to be used.
See also RAND, SPRAND, SPRANDN, RANDPERM.
BAR Bar
graph.
BAR(X,Y) draws the columns of the MbyN matrix Y as M groups of N
vertical bars. The vector X must be monotonically increasing or
decreasing.
BAR(Y) uses the default value of X=1:M. For vector inputs, BAR(X,Y)
or BAR(Y) draws LENGTH(Y) bars. The colors are set by the colormap.
BAR(X,Y,WIDTH) or BAR(Y,WIDTH) specifies the width of the bars. Values
of WIDTH > 1, produce overlapped bars. The default value is WIDTH=0.8
BAR(...,'grouped') produces the default vertical grouped bar chart.
BAR(...,'stacked') produces a vertical stacked bar chart.
BAR(...,LINESPEC) uses the line color specified (one of 'rgbymckw').
H = BAR(...) returns a vector of patch handles.
Use SHADING FACETED to put edges on the bars. Use SHADING FLAT to
turn them off.
Examples: subplot(3,1,1), bar(rand(10,5),'stacked'), colormap(cool)
subplot(3,1,2), bar(0:.25:1,rand(5),1)
subplot(3,1,3), bar(rand(2,3),.75,'grouped')
See also HIST, PLOT, BARH.
BARH
Horizontal bar graph.
BARH(X,Y) draws the columns of the MbyN matrix Y as M groups of
N horizontal bars. The vector X must be monotonically increasing
or decreasing.
BARH(Y) uses the default value of X=1:M. For vector inputs,
BARH(X,Y) or BARH(Y) draws LENGTH(Y) bars. The colors are set by
the colormap.
BARH(X,Y,WIDTH) or BARH(Y,WIDTH) specifies the width of the
bars. Values of WIDTH > 1, produce overlapped bars. The
default value is WIDTH=0.8.
BARH(...,'grouped') produces the default vertical grouped bar chart.
BARH(...,'stacked') produces a vertical stacked bar chart.
BARH(...,LINESPEC) uses the line color specified (one of 'rgbymckw').
H = BARH(...) returns a vector of patch handles.
Use SHADING FACETED to put edges on the bars. Use SHADING FLAT to
turn them off.
Examples: subplot(3,1,1), barh(rand(10,5),'stacked'), colormap(cool)
subplot(3,1,2), barh(0:.25:1,rand(5),1)
subplot(3,1,3), barh(rand(2,3),.75,'grouped')
See also PLOT, BAR, BAR3H.
CONTOUR
Contour plot.
CONTOUR(Z) is a contour plot of matrix Z treating the values in Z
as heights above a plane. A contour plot are the level curves
of Z for some values V. The values V are chosen automatically.
CONTOUR(X,Y,Z) X and Y specify the (x,y) coordinates of the
surface as for SURF.
CONTOUR(Z,N) and CONTOUR(X,Y,Z,N) draw N contour lines,
overriding the automatic value.
CONTOUR(Z,V) and CONTOUR(X,Y,Z,V) draw LENGTH(V) contour lines
at the values specified in vector V. Use CONTOUR(Z,[v v]) or
CONTOUR(X,Y,Z,[v v]) to compute a single contour at the level v.
[C,H] = CONTOUR(...) returns contour matrix C as described in
CONTOURC and a column vector H of handles to LINE or PATCH
objects, one handle per line. Both of these can be used as
input to CLABEL. The UserData property of each object contains the
height value for each contour.
The contours are normally colored based on the current colormap
and are drawn as PATCH objects. You can override this behavior
with the syntax CONTOUR(...,'LINESPEC') to draw the contours as
LINE objects with the color and linetype specified.
Uses code by R. Pawlowicz to handle parametric surfaces and
inline contour labels.
Example:
[c,h] = contour(peaks); clabel(c,h), colorbar
See also CONTOUR3, CONTOURF, CLABEL, COLORBAR.
MESHC
Combination mesh/contour plot.
MESHC(...) is the same as MESH(...) except that a contour plot
is drawn beneath the mesh.
Because CONTOUR does not handle irregularly spaced data, this
routine only works for surfaces defined on a rectangular grid.
The matrices or vectors X and Y define the axis limits only.
See also MESH.
SURFC
Combination surf/contour plot.
SURFC(...) is the same as SURF(...) except that a contour plot
is drawn beneath the surface.
See also SURF, SHADING.
VIEW 3D
graph viewpoint specification.
VIEW(AZ,EL) and VIEW([AZ,EL]) set the angle of the view from which an
observer sees the current 3D plot. AZ is the azimuth or horizontal
rotation and EL is the vertical elevation (both in degrees). Azimuth
revolves about the zaxis, with positive values indicating counter
clockwise rotation of the viewpoint. Positive values of elevation
correspond to moving above the object; negative values move below.
VIEW([X Y Z]) sets the view angle in cartesian coordinates. The
magnitude of vector X,Y,Z is ignored.
Here are some examples:
AZ = 37.5, EL = 30 is the default 3D view.
AZ = 0, EL = 90 is directly overhead and the default 2D view.
AZ = EL = 0 looks directly up the first column of the matrix.
AZ = 180 is behind the matrix.
VIEW(2) sets the default 2D view, AZ = 0, EL = 90.
VIEW(3) sets the default 3D view, AZ = 37.5, EL = 30.
[AZ,EL] = VIEW returns the current azimuth and elevation.
VIEW(T) accepts a 4by4 transformation matrix, such as
the perspective transformations generated by VIEWMTX.
T = VIEW returns the current general 4by4 transformation matrix.
See also VIEWMTX, the AXES properties View, Xform.
SURF 3D
colored surface.
SURF(X,Y,Z,C) plots the colored parametric surface 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.
The shading model is set by SHADING.
SURF(X,Y,Z) uses C = Z, so color is proportional to surface height.
SURF(x,y,Z) and SURF(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 surface patches are the triples (x(j), y(i), Z(i,j)).
Note that x corresponds to the columns of Z and y corresponds to
the rows.
SURF(Z) and SURF(Z,C) use x = 1:n and y = 1:m. In this case,
the height, Z, is a singlevalued function, defined over a
geometrically rectangular grid.
SURF 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 surface.
See also SURFC, SURFL, MESH, SHADING.
FORMAT Set
output format.
All computations in MATLAB are done in double precision.
FORMAT may be used to switch between different output
display formats as follows:
FORMAT Default. Same as SHORT.
FORMAT SHORT Scaled fixed point format with 5 digits.
FORMAT LONG Scaled fixed point format with 15 digits.
FORMAT SHORT E Floating point format with 5 digits.
FORMAT LONG E Floating point format with 15 digits.
FORMAT SHORT G Best of fixed or floating point format with 5 digits.
FORMAT LONG G Best of fixed or floating point format with 15 digits.
FORMAT HEX Hexadecimal format.
FORMAT + The symbols +,  and blank are printed
for positive, negative and zero elements.
Imaginary parts are ignored.
FORMAT BANK Fixed format for dollars and cents.
FORMAT RAT Approximation by ratio of small integers.
Spacing:
FORMAT COMPACT Suppress extra linefeeds.
FORMAT LOOSE Puts the extra linefeeds back in.
POLY Convert
roots to polynomial.
POLY(A), when A is an N by N matrix, is a row vector with
N+1 elements which are the coefficients of the
characteristic polynomial, DET(lambda*EYE(SIZE(A))  A) .
POLY(V), when V is a vector, is a vector whose elements are
the coefficients of the polynomial whose roots are the
elements of V . For vectors, ROOTS and POLY are inverse
functions of each other, up to ordering, scaling, and
roundoff error.
ROOTS(POLY(1:20)) generates Wilkinson's famous example.
See also ROOTS, CONV, RESIDUE, POLYVAL.
Overloaded methods
help sym/poly.m
POLYVAL
Evaluate polynomial.
Y = POLYVAL(P,X), when P is a vector of length N+1 whose elements
are the coefficients of a polynomial, is the value of the
polynomial evaluated at X.
Y = P(1)*X^N + P(2)*X^(N1) + ... + P(N)*X + P(N+1)
If X is a matrix or vector, the polynomial is evaluated at all
points in X. See also POLYVALM for evaluation in a matrix sense.
[Y,DELTA] = POLYVAL(P,X,S) uses the optional output structure
generated by POLYFIT to generate error estimates, Y +/ delta.
If the errors in the data input to POLYFIT are independent normal
with constant variance, Y +/ DELTA contains at least 50% of the
predictions.
See also POLYFIT, POLYVALM.
POLYFIT
Fit polynomial to data.
POLYFIT(X,Y,N) finds the coefficients of a polynomial P(X) of
degree N that fits the data, P(X(I))~=Y(I), in a leastsquares sense.
[P,S] = POLYFIT(X,Y,N) returns the polynomial coefficients P and a
structure S for use with POLYVAL to obtain error estimates on
predictions. If the errors in the data, Y, are independent normal
with constant variance, POLYVAL will produce error bounds which
contain at least 50% of the predictions.
See also POLY, POLYVAL, ROOTS.
ROOTS Find
polynomial roots.
ROOTS(C) computes the roots of the polynomial whose coefficients
are the elements of the vector C. If C has N+1 components,
the polynomial is C(1)*X^N + ... + C(N)*X + C(N+1).
See also POLY, RESIDUE, FZERO.
SUM Sum of elements.
For vectors, SUM(X) is the sum of the elements of X. For
matrices, SUM(X) is a row vector with the sum over each
column. For ND arrays, SUM(X) operates along the first
nonsingleton dimension.
SUM(X,DIM) sums along the dimension DIM.
Example: If X = [0 1 2
3 4 5]
then sum(X,1) is [3 5 7] and sum(X,2) is [ 3
12];
See also PROD, CUMSUM, DIFF.
Overloaded methods
help sym/sum.m
FOR Repeat
statements a specific number of times.
The general form of a FOR statement is:
FOR variable = expr, statement, ..., statement END
The columns of the expression are stored one at a time in
the variable and then the following statements, up to the
END, are executed. The expression is often of the form X:Y,
in which case its columns are simply scalars. Some examples
(assume N has already been assigned a value).
FOR I = 1:N,
FOR J = 1:N,
A(I,J) = 1/(I+J1);
END
END
FOR S = 1.0: 0.1: 0.0, END steps S with increments of 0.1
FOR E = EYE(N), ... END sets E to the unit Nvectors.
The BREAK statement can be used to terminate the loop prematurely.
See also IF, WHILE, SWITCH, BREAK, END.
WHILE
Repeat statements an indefinite number of times.
The general form of a WHILE statement is:
WHILE expression
statements
END
The statements are executed while the real part of the expression
has all nonzero elements. The expression is usually the result of
expr rop expr where rop is ==, <, >, <=, >=, or ~=.
The BREAK statement can be used to terminate the loop prematurely.
For example (assuming A already defined):
E = 0*A; F = E + eye(size(E)); N = 1;
while norm(E+FE,1) > 0,
E = E + F;
F = A*F/N;
N = N + 1;
end
See also FOR, IF, SWITCH, BREAK, END.
