1 Functions — By Categoryuser-defined options Command Window and History commandhistory Open Command History window, or select it if already opencommandwindow Open Command Window, or sel
Trang 1MATLAB ® 7
Function Reference: Volume 1 (A-E)
Trang 2How to Contact The MathWorks
www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
www.mathworks.com/contact_TS.html Technical Support
suggest@mathworks.com Product enhancement suggestions
bugs@mathworks.com Bug reports
doc@mathworks.com Documentation error reports
service@mathworks.com Order status, license renewals, passcodesinfo@mathworks.com Sales, pricing, and general information
508-647-7000 (Phone)
508-647-7001 (Fax)
The MathWorks, Inc.
3 Apple Hill Drive
Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site
MATLAB Function Reference
© COPYRIGHT 1984–2007 by The MathWorks, Inc
The software described in this document is furnished under a license agreement The software may be used
or copied only under the terms of the license agreement No part of this manual may be photocopied or reproduced in any form without prior written consent from The MathWorks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation
by, for, or through the federal government of the United States By accepting delivery of the Program or Documentation, the government hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer software documentation as such terms are used or defined
in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014 Accordingly, the terms and conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern the use, modification, reproduction, release, performance, display, and disclosure of the Program and Documentation
by the federal government (or other entity acquiring for or through the federal government) and shall supersede any conflicting contractual terms or conditions If this License fails to meet the government’s needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Documentation, unused, to The MathWorks, Inc.
Trademarks
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology,
SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The
MathWorks, the L-shaped membrane logo, Embedded MATLAB, and PolySpace are
trademarks of The MathWorks, Inc.
Other product or brand names are trademarks or registered trademarks of their respective holders.
Trang 3Revision History
December 1996 First printing For MATLAB 5.0 (Release 8)
June 1997 Online only Revised for MATLAB 5.1 (Release 9) October 1997 Online only Revised for MATLAB 5.2 (Release 10) January 1999 Online only Revised for MATLAB 5.3 (Release 11) June 1999 Second printing For MATLAB 5.3 (Release 11)
June 2001 Online only Revised for MATLAB 6.1 (Release 12.1) July 2002 Online only Revised for 6.5 (Release 13)
June 2004 Online only Revised for 7.0 (Release 14)
September 2006 Online only Revised for 7.3 (Release 2006b) September 2007 Online only Revised for 7.5 (Release 2007b)
Trang 5Functions — By Category 1
Desktop Tools and Development Environment . 1-3
Startup and Shutdown . 1-3
Command Window and History . 1-4
Help for Using MATLAB . 1-5
Workspace, Search Path, and File Operations . 1-6
Interpolation and Computational Geometry . 1-28
Cartesian Coordinate System Conversion . 1-31
Nonlinear Numerical Methods . 1-31
Filtering and Convolution . 1-42
Interpolation and Regression . 1-42
Fourier Transforms . 1-43
Derivatives and Integrals . 1-43
Time Series Objects . 1-44
Time Series Collections . 1-47
Programming and Data Types . 1-49
Data Types . 1-49
Data Type Conversion . 1-58
Trang 6File Name Construction . 1-76
Opening, Loading, Saving Files . 1-77
Creating Graphical User Interfaces . 1-104
Predefined Dialog Boxes . 1-104
Deploying User Interfaces . 1-105
Developing User Interfaces . 1-105
Trang 7Finding Objects from Callbacks . 1-107
GUI Utility Functions . 1-107
Controlling Program Execution . 1-108
Serial Port Devices . 1-113
Functions — Alphabetical List 2
Index
Trang 9Mathematics (p 1-13) Arrays and matrices, linear algebra,
other areas of mathematicsData Analysis (p 1-41) Basic data operations, descriptive
statistics, covariance and correlation,filtering and convolution, numericalderivatives and integrals, Fouriertransforms, time series analysisProgramming and Data Types
(p 1-49)
Function/expression evaluation,program control, function handles,object oriented programming, errorhandling, operators, data types,dates and times, timers
File I/O (p 1-76) General and low-level file I/O, plus
specific file formats, like audio,spreadsheet, HDF, imagesGraphics (p 1-86) Line plots, annotating graphs,
specialized plots, images, printing,Handle Graphics
3-D Visualization (p 1-97) Surface and mesh plots, view control,
lighting and transparency, volumevisualization
Trang 10External Interfaces (p 1-109) Interfaces to DLLs, Java, COM and
ActiveX, Web services, and serialport devices, and C and Fortranroutines
Trang 11Desktop Tools and Development Environment
Desktop Tools and Development Environment
Startup and Shutdown (p 1-3) Startup and shutdown options,
preferencesCommand Window and History
(p 1-4)
Control Command Window andHistory, enter statements and runfunctions
Help for Using MATLAB (p 1-5) Command line help, online
documentation in the Help browser,demos
Workspace, Search Path, and FileOperations (p 1-6)
Work with files, MATLAB searchpath, manage variables
Programming Tools (p 1-8) Edit and debug M-files, improve
performance, source control, publishresults
System (p 1-11) Identify current computer, license,
product version, and more
Startup and Shutdown
matlab (UNIX) Start MATLAB (UNIX systems)matlab (Windows) Start MATLAB (Windows systems)
single-user systems or systemadministrators
prefdir Directory containing preferences,
history, and layout filespreferences Open Preferences dialog box for
MATLAB and related products
Trang 121 Functions — By Category
user-defined options
Command Window and History
commandhistory Open Command History window, or
select it if already opencommandwindow Open Command Window, or select it
if already open
resultformat Set display format for outputhome Move cursor to upper-left corner of
Command Windowmatlabcolon (matlab:) Run specified function via hyperlink
Windowperl Call Perl script using appropriate
operating system executablesystem Execute operating system command
and return result
result
Trang 13Desktop Tools and Development Environment
Help for Using MATLAB
builddocsearchdb Build searchable documentation
database
browser
docsearch Open Help browser Search pane
and search for specified termechodemo Run M-file demo step-by-step in
Command Window
Command Windowhelpbrowser Open Help browser to access all
online documentation and demoshelpwin Provide access to M-file help for all
functions
MathWorkslookfor Search for keyword in all help
entriesplayshow Run M-file demo (deprecated; use
support Open MathWorks Technical Support
Web pageweb Open Web site or file in Web browser
or Help browserwhatsnew Release Notes for MathWorks
products
Trang 141 Functions — By Category
Workspace, Search Path, and File Operations
Workspace (p 1-6) Manage variablesSearch Path (p 1-6) View and change MATLAB search
pathFile Operations (p 1-7) View and change files and directories
Workspace
assignin Assign value to variable in specified
workspace
freeing up system memory
specified workspaceexist Check existence of variable, function,
directory, or Java classopenvar Open workspace variable in Array
Editor or other tool for graphicalediting
uiimport Open Import Wizard to import data
workspace Open Workspace browser to manage
Trang 15Desktop Tools and Development Environment
search pathpath2rc Save current MATLAB search path
pathdef Directories in MATLAB search path
pathsep Path separator for current platform
pathtool Open Set Path dialog box to view
and change MATLAB pathrestoredefaultpath Restore default MATLAB search
path
search pathsavepath Save current MATLAB search path
File Operations
See also “File I/O” on page 1-76 functions
delete Remove files or graphics objects
exist Check existence of variable, function,
directory, or Java classfileattrib Set or get attributes of file or
directoryfilebrowser Current Directory browser
directorylookfor Search for keyword in all help
Trang 161 Functions — By Category
matlabroot Root directory of MATLAB
installation
recycle Set option to move deleted files to
recycle folderrehash Refresh function and file system
path caches
toolboxdir Root directory for specified toolbox
web Open Web site or file in Web browser
control systemPublishing (p 1-10) Publish M-file code and results
Trang 17Desktop Tools and Development Environment
Edit and Debug M-Files
clipboard Copy and paste strings to and from
system clipboarddatatipinfo Produce short description of input
variable
when in debug mode
dbstep Execute one or more lines from
current breakpoint
dbtype List M-file with line numbers
debug List M-file debugging functions
Improve Performance and Tune M-Files
mlint Check M-files for possible problems
mlintrpt Run mlint for file or directory,
reporting results in browser
Trang 181 Functions — By Category
profsave Save profile report in HTML formatrehash Refresh function and file system
path caches
Source Control
checkin Check files into source control
system (UNIX)checkout Check files out of source control
system (UNIX)cmopts Name of source control systemcustomverctrl Allow custom source control system
(UNIX)undocheckout Undo previous checkout from source
control system (UNIX)verctrl Source control actions (Windows)
Publishing
published to HTMLnotebook Open M-book in Microsoft Word
(Windows)publish Publish M-file containing cells,
saving output to file of specified type
Trang 19Desktop Tools and Development Environment
System
Operating System Interface (p 1-11) Exchange operating system
information and commands withMATLAB
MATLAB Version and License
(p 1-12)
Information about MATLAB versionand license
Operating System Interface
clipboard Copy and paste strings to and from
system clipboardcomputer Information about computer on
which MATLAB is running
result
hostid MATLAB server host identification
numbermaxNumCompThreads Controls maximum number of
computational threadsperl Call Perl script using appropriate
operating system executable
system Execute operating system command
and return result
resultwinqueryreg Item from Microsoft Windows
registry
Trang 201 Functions — By Category
MATLAB Version and License
Macintosh OS X versions ofMATLAB
version of MATLABisstudent Determine whether Student Version
of MATLABisunix Determine whether UNIX version of
MATLABjavachk Generate error message based on
Java feature supportlicense Return license number or perform
licensing taskprefdir Directory containing preferences,
history, and layout filesusejava Determine whether Java feature is
supported in MATLAB
productsverLessThan Compare toolbox version to specified
version string
Trang 21Mathematics
Arrays and Matrices (p 1-14) Basic array operators and operations,
creation of elementary andspecialized arrays and matricesLinear Algebra (p 1-19) Matrix analysis, linear equations,
eigenvalues, singular values,logarithms, exponentials,factorization
Elementary Math (p 1-23) Trigonometry, exponentials and
logarithms, complex values,rounding, remainders, discrete mathPolynomials (p 1-28) Multiplication, division, evaluation,
roots, derivatives, integration,eigenvalue problem, curve fitting,partial fraction expansion
Interpolation and ComputationalGeometry (p 1-28)
Interpolation, Delaunaytriangulation and tessellation,convex hulls, Voronoi diagrams,domain generation
Cartesian Coordinate SystemConversion (p 1-31)
Conversions between Cartesian andpolar or spherical coordinatesNonlinear Numerical Methods
(p 1-31)
Differential equations, optimization,integration
Specialized Math (p 1-35) Airy, Bessel, Jacobi, Legendre, beta,
elliptic, error, exponential integral,gamma functions
Sparse Matrices (p 1-36) Elementary sparse matrices,
operations, reordering algorithms,linear algebra, iterative methods,tree operations
Math Constants (p 1-39) Pi, imaginary unit, infinity,
Not-a-Number, largest and smallestpositive floating point numbers,
Trang 221 Functions — By Category
Arrays and Matrices
Basic Information (p 1-14) Display array contents, get array
information, determine array typeOperators (p 1-15) Arithmetic operators
Elementary Matrices and Arrays(p 1-16)
Create elementary arrays of differenttypes, generate arrays for plotting,array indexing, etc
Array Operations (p 1-17) Operate on array content, apply
function to each array element, findcumulative product or sum, etc.Array Manipulation (p 1-17) Create, sort, rotate, permute,
reshape, and shift array contentsSpecialized Matrices (p 1-18) Create Hadamard, Companion,
Hankel, Vandermonde, Pascalmatrices, etc
Basic Information
display Display text or array (overloaded
method)isempty Determine whether array is empty
isequalwithequalnans Test arrays for equality, treating
NaNs as equalisfinite Array elements that are finite
floating-point arrayisinf Array elements that are infiniteisinteger Determine whether input is integer
array
Trang 23islogical Determine whether input is logical
array
isnumeric Determine whether input is numeric
arrayisscalar Determine whether input is scalar
issparse Determine whether input is sparse
isvector Determine whether input is vector
subscripted array expression
\ Backslash or left matrix divide
/ Slash or right matrix divide
.’ Nonconjugated transpose
Trang 241 Functions — By Category
.^ Array power (element-wise).\ Left array divide (element-wise)./ Right array divide (element-wise)
Elementary Matrices and Arrays
blkdiag Construct block diagonal matrix
from input argumentsdiag Diagonal matrices and diagonals of
matrix
freqspace Frequency spacing for frequency
responseind2sub Subscripts from linear indexlinspace Generate linearly spaced vectorslogspace Generate logarithmically spaced
vectorsmeshgrid GenerateXandYarrays for 3-D plotsndgrid Generate arrays for N-D functions
and interpolation
pseudorandom numbers
numberssub2ind Single index from subscripts
Trang 25Array Operations
See “Linear Algebra” on page 1-19 and “Elementary Math” on page 1-23 for
other array operations
accumarray Construct array with accumulation
arrayfun Apply function to each element of
arraybsxfun Apply element-by-element binary
operation to two arrays withsingleton expansion enabledcast Cast variable to different data type
idivide Integer division with rounding
option
Array Manipulation
blkdiag Construct block diagonal matrix
from input arguments
dimensioncircshift Shift array circularly
Trang 261 Functions — By Category
diag Diagonal matrices and diagonals of
matrixend Terminate block of code, or indicate
last array indexflipdim Flip array along specified dimension
horzcat Concatenate arrays horizontally
ipermute Inverse permute dimensions of N-D
arraypermute Rearrange dimensions of N-D array
sort Sort array elements in ascending or
descending ordersortrows Sort rows in ascending order
vertcat Concatenate arrays vertically
Specialized Matrices
Trang 27rosser Classic symmetric eigenvalue test
problem
wilkinson Wilkinson’s eigenvalue test matrix
Linear Algebra
Matrix Analysis (p 1-19) Compute norm, rank, determinant,
condition number, etc
Linear Equations (p 1-20) Solve linear systems, least
squares, LU factorization, Choleskyfactorization, etc
Eigenvalues and Singular Values
(p 1-21)
Eigenvalues, eigenvectors, Schurdecomposition, Hessenburgmatrices, etc
Matrix Logarithms and Exponentials
(p 1-22)
Matrix logarithms, exponentials,square root
Factorization (p 1-22) Cholesky, LU, and QR factorizations,
diagonal forms, singular valuedecomposition
Matrix Analysis
inversioncondeig Condition number with respect to
Trang 281 Functions — By Category
rcond Matrix reciprocal condition number
estimate
subspace Angle between two subspaces
Linear Equations
cholinc Sparse incomplete Cholesky and
Cholesky-Infinity factorizations
inversioncondest 1-norm condition number estimate
linsolve Solve linear system of equationslscov Least-squares solution in presence
of known covariancelsqnonneg Solve nonnegative least-squares
constraints problem
Trang 29luinc Sparse incomplete LU factorization
matrix
decompositionrcond Matrix reciprocal condition number
estimate
Eigenvalues and Singular Values
eigenvalue accuracycdf2rdf Convert complex diagonal form to
real block diagonal formcondeig Condition number with respect to
eigenvalues
eigenvectors of sparse matrix
decomposition
ordeig Eigenvalues of quasitriangular
matrices
factorizationordschur Reorder eigenvalues in Schur
factorization
polyeig Polynomial eigenvalue problem
Trang 301 Functions — By Category
rsf2csf Convert real Schur form to complex
Schur form
parameters to transfer functionform
Matrix Logarithms and Exponentials
Factorization
eigenvalue accuracycdf2rdf Convert complex diagonal form to
real block diagonal form
cholinc Sparse incomplete Cholesky and
Cholesky-Infinity factorizationscholupdate Rank 1 update to Cholesky
Trang 31luinc Sparse incomplete LU factorization
decomposition
factorizationqrinsert Insert column or row into QR
factorizationqrupdate
eigenvaluesrsf2csf Convert real Schur form to complex
root functionsComplex (p 1-26) Numbers with real and imaginary
components, phase anglesRounding and Remainder (p 1-27) Rounding, modulus, and remainder
Discrete Math (e.g., Prime Factors)
(p 1-27)
Prime factors, factorials,permutations, rational fractions,least common multiple, greatestcommon divisor
Trang 321 Functions — By Category
Trigonometric
acos Inverse cosine; result in radiansacosd Inverse cosine; result in degrees
acot Inverse cotangent; result in radiansacotd Inverse cotangent; result in degrees
acsc Inverse cosecant; result in radiansacscd Inverse cosecant; result in degrees
asec Inverse secant; result in radiansasecd Inverse secant; result in degrees
asin Inverse sine; result in radiansasind Inverse sine; result in degrees
atan Inverse tangent; result in radians
atand Inverse tangent; result in degrees
Trang 33radians
Exponential
small values ofx
small values ofx
floating-point numbers intoexponent and mantissa
nthroot Realnth root of real numbers
pow2 Base 2 power and scale floating-point
Trang 341 Functions — By Category
reallog Natural logarithm for nonnegative
real arraysrealpow Array power for real-only outputrealsqrt Square root for nonnegative real
complex Construct complex data from real
and imaginary components
cplxpair Sort complex numbers into complex
conjugate pairs
isreal Determine whether input is real
array
unwrap Correct phase angles to produce
smoother phase plots
Trang 35Rounding and Remainder
idivide Integer division with rounding
option
Discrete Math (e.g., Prime Factors)
isprime Array elements that are prime
numbers
nchoosek Binomial coefficient or all
combinations
primes Generate list of prime numbers
rat, rats Rational fraction approximation
Trang 36polyeig Polynomial eigenvalue problem
polyint Integrate polynomial analytically
polyvalm Matrix polynomial evaluationresidue Convert between partial fraction
expansion and polynomialcoefficients
Interpolation and Computational Geometry
Interpolation (p 1-29) Data interpolation, data gridding,
polynomial evaluation, nearest pointsearch
Delaunay Triangulation andTessellation (p 1-30)
Delaunay triangulation andtessellation, triangular surface andmesh plots
Convex Hull (p 1-30) Plot convex hull, plotting functionsVoronoi Diagrams (p 1-30) Plot Voronoi diagram, patch graphics
object, plotting functionsDomain Generation (p 1-31) Generate arrays for 3-D plots, or for
N-D functions and interpolation
Trang 37Interpolation
dsearch Search Delaunay triangulation for
nearest point
griddata3 Data gridding and hypersurface
fitting for 3-D datagriddatan Data gridding and hypersurface
fitting (dimension >= 2)interp1 1-D data interpolation (table lookup)
interp1q Quick 1-D linear interpolation
interp2 2-D data interpolation (table lookup)
interp3 3-D data interpolation (table lookup)
interpft 1-D interpolation using FFT method
interpn N-D data interpolation (table lookup)
meshgrid GenerateXandYarrays for 3-D plots
ndgrid Generate arrays for N-D functions
and interpolationpadecoef Padé approximation of time delays
Interpolating Polynomial (PCHIP)
spline Cubic spline data interpolation
tsearchn N-D closest simplex search
Trang 381 Functions — By Category
Delaunay Triangulation and Tessellation
delaunay3 3-D Delaunay tessellationdelaunayn N-D Delaunay tessellationdsearch Search Delaunay triangulation for
nearest point
tsearch Search for enclosing Delaunay
triangletsearchn N-D closest simplex search
Convex Hull
Trang 39Domain Generation
meshgrid GenerateXandYarrays for 3-D plots
ndgrid Generate arrays for N-D functions
and interpolation
Cartesian Coordinate System Conversion
cart2pol Transform Cartesian coordinates to
polar or cylindricalcart2sph Transform Cartesian coordinates to
sphericalpol2cart Transform polar or cylindrical
coordinates to Cartesiansph2cart Transform spherical coordinates to
Cartesian
Nonlinear Numerical Methods
Ordinary Differential Equations
(IVP) (p 1-32)
Solve stiff and nonstiff differentialequations, define the problem, setsolver options, evaluate solutionDelay Differential Equations
(p 1-33)
Solve delay differential equationswith constant and general delays,set solver options, evaluate solutionBoundary Value Problems (p 1-33) Solve boundary value problems for
ordinary differential equations, setsolver options, evaluate solution
Trang 40Optimization (p 1-34) Find minimum of single and
multivariable functions, solvenonnegative least-squares constraintproblem
Numerical Integration (Quadrature)(p 1-34)
Evaluate Simpson, Lobatto, andvectorized quadratures, evaluatedouble and triple integrals
Ordinary Differential Equations (IVP)
decic Compute consistent initial conditions
deval Evaluate solution of differential
equation problemode15i Solve fully implicit differential
equations, variable order methodode23, ode45, ode113, ode15s,
ode23s, ode23t, ode23tb
Solve initial value problems forordinary differential equationsodefile Define differential equation problem
for ordinary differential equationsolvers
odeget Ordinary differential equation
options parametersodeset Create or alter options structure
for ordinary differential equationsolvers
odextend Extend solution of initial value
problem for ordinary differentialequation