M ATLAB ® The Language of Technical Computing Computation Visualization Programming MATLAB Function Reference Volume 3: P - Z Version 6 How to Contact The MathWorks: www.mathworks.com Web comp.soft-sys.matlab Newsgroup [email protected] Technical support [email protected] Product enhancement suggestions [email protected] Bug reports [email protected] Documentation error reports [email protected] Order status, license renewals, passcodes [email protected] Sales, pricing, and general information 508-647-7000 Phone 508-647-7001 Fax The MathWorks, Inc. Mail 3 Apple Hill Drive Natick, MA 01760-2098 For contact information about worldwide offices, see the MathWorks Web site. MATLAB Function Reference Volume 3: P - Z COPYRIGHT 1984 - 2001 by The MathWorks, Inc. Thesoftwaredescribedinthisdocumentisfurnishedunderalicenseagreement. Thesoftwaremaybeused orcopiedonlyunderthetermsofthelicenseagreement.Nopartofthismanualmaybephotocopiedorrepro- duced in any form without prior written consent from The MathWorks, Inc. FEDERALACQUISITION: ThisprovisionappliestoallacquisitionsoftheProgramandDocumentationby or for the federal government of the United States. By accepting delivery of the Program, the government hereby agrees that this software qualifies as "commercial" computer software within the meaning of FAR Part12.212,DFARSPart227.7202-1,DFARSPart227.7202-3,DFARSPart252.227-7013,andDFARSPart 252.227-7014. ThetermsandconditionsofTheMathWorks,Inc.SoftwareLicenseAgreementshallpertain to the government’s use and disclosure of the Program and Documentation, and shall supersede any conflictingcontractualtermsorconditions. Ifthislicensefailstomeetthegovernment’sminimumneedsor is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Documentation, unused, to MathWorks. MATLAB,Simulink,Stateflow,HandleGraphics,andReal-TimeWorkshopareregisteredtrademarks,and Target Language Compiler is a trademark of The MathWorks, Inc. Other product or brand names are trademarks or registered trademarks of their respective holders. Printing History: December 1996First printing (for MATLAB 5) June 1997 Revised for 5.1 (online version) October 1997 Revised for 5.2 (online version) January 1999 Revised for Release 11 (online version) June 1999 Printed for Release 11 March 2000 Beta (online only) June 2001 Revised for 6.1 (online version) Contents Functions By Category 1 Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3 Starting and Quitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3 Command Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3 Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Workspace, File, and Search Path . . . . . . . . . . . . . . . . . . . . . . . 1-4 Programming Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5 System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6 Performance Improvement Tools and Techniques . . . . . . . . . . 1-6 Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7 Arrays and Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8 Linear Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-10 Elementary Math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12 Data Analysis and Fourier Transforms . . . . . . . . . . . . . . . . . . 1-14 Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15 Interpolation and Computational Geometry . . . . . . . . . . . . . . 1-16 Coordinate System Conversion . . . . . . . . . . . . . . . . . . . . . . . . . 1-17 Nonlinear Numerical Methods . . . . . . . . . . . . . . . . . . . . . . . . . 1-17 Specialized Math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-18 Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-19 Math Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-21 Programming and Data Types . . . . . . . . . . . . . . . . . . . . . . . . 1-22 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-22 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-26 Operators and Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-27 Programming in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-30 File I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-34 Filename Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-34 Opening, Loading, Saving Files . . . . . . . . . . . . . . . . . . . . . . . . 1-34 Low-Level File I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-35 Text Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-35 Spreadsheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-35 i Scientific Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-36 Audio and Audio/Video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-36 Images. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-37 Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-38 Basic Plots and Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-38 Annotating Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-38 Specialized Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-39 Bit-Mapped Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-41 Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-41 Handle Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-41 3-D Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-43 Surface and Mesh Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-43 View Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-44 Lighting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-45 Transparency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-46 Volume Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-46 Creating Graphical User Interfaces . . . . . . . . . . . . . . . . . . . . 1-47 Predefined Dialog Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-47 Deploying User Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-48 Developing User Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-48 User Interface Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-48 Finding and Identifying Objects . . . . . . . . . . . . . . . . . . . . . . . . 1-48 GUI Utility Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-48 Controlling Program Execution. . . . . . . . . . . . . . . . . . . . . . . . . 1-49 Alphabetical List of Functions 2 ii Contents 1 Functions By Category 1 Functions By Category The MATLAB Function Reference contains descriptions of all MATLAB commands and functions. Ifyouknowthenameofafunction,usethe“AlphabeticalListofFunctions”to find the reference page. Ifyoudonotknowthenameofafunction,selectacategoryfromthefollowing table to see a list of related functions. You can also browse these tables to see what functionality MATLAB provides. Category Description Development Environment Startup, Command Window, help, editing and debugging, other general functions Mathematics Arrays and matrices, linear algebra, data analysis, other areas of mathematics Programming and Data Function/expression evaluation, program Types control, function handles, object oriented programming, error handling, operators, data types File I/O General and low-level file I/O, plus specific file formats, like audio, spreadsheet, HDF, images Graphics Line plots, annotating graphs, specialized plots, images, printing, Handle Graphics 3-D Visualization Surface and mesh plots, view control, lighting and transparency, volume visualization. Creating Graphical User GUIDE, programming graphical user Interface interfaces. External Interfaces Java, ActiveX, Serial Port functions. SeeSimulink,Stateflow,Real-TimeWorkshop,andtheindividualtoolboxesfor lists of their functions 1-2 Development Environment Development Environment General functions for working in MATLAB, including functions for startup, Command Window, help, and editing and debugging. Category Description “StartingandQuitting” Startup and shutdown options “Command Window” Controlling Command Window “Getting Help” Methods for finding information “Workspace, File, and File, search path, variable management Search Path” “Programming Tools” Editing and debugging, source control, profiling “System” Identifyingcurrentcomputer,license,orproduct version “Performance Improving and assessing performance, e.g., Improvement Tools memory use and Techniques” Starting and Quitting exit Terminate MATLAB (same asquit) finish MATLAB termination M-file matlab Start MATLAB (UNIX systems only) matlabrc MATLAB startup M-file for single user systems or administrators quit Terminate MATLAB startup MATLAB startup M-file for user-defined options Command Window clc Clear Command Window diary Save session to file dos Execute DOS command and return result format Control display format for output home Move cursor to upper left corner of Command Window more Control paged output for Command Window 1-3 1 Functions By Category notebook Open M-book in Microsoft Word (Windows only) unix Execute UNIX command and return result Getting Help doc Display online documentation in MATLAB Help browser docopt Location of help file directory for UNIX platforms help Display help for MATLAB functions in Command Window helpbrowser Display Help browser for access to extensive online help helpwin Display M-file help, with access to M-file help for all functions info Display information about The MathWorks or products lookfor Search for specified keyword in all help entries support Open MathWorks Technical Support Web page web Point Help browser or Web browser to file or Web site whatsnew Display information about MATLAB and toolbox releases Workspace, File, and Search Path •“Workspace” •“File” •“Search Path” Workspace assignin Assign value to workspace variable clear Remove items from workspace, freeing up system memory evalin Execute string containing MATLAB expression in a workspace exist Check if variable or file exists openvar Open workspace variable in Array Editor for graphical editing pack Consolidate workspace memory which Locate functions and files who,whos List variables in the workspace workspace Display Workspace browser, a tool for managing the workspace File cd Change working directory copyfile Copy file delete Delete files or graphics objects dir Display directory listing exist Check if a variable or file exists filebrowser Display Current Directory browser, a tool for viewing files lookfor Search for specified keyword in all help entries 1-4 Development Environment ls List directory on UNIX matlabroot Return root directory of MATLAB installation mkdir Make new directory pwd Display current directory rehash Refresh function and file system caches type List file what List MATLAB specific files in current directory which Locate functions and files See also “File I/O” functions. Search Path addpath Add directories to MATLAB search path genpath Generate path string partialpath Partial pathname path View or change the MATLAB directory search path pathtool OpenSet Path dialog box to view and change MATLAB path rmpath Remove directories from MATLAB search path Programming Tools •“Editing and Debugging” •“Source Control” •“Profiling” Editing and Debugging dbclear Clear breakpoints dbcont Resume execution dbdown Change local workspace context dbquit Quit debug mode dbstack Display function call stack dbstatus List all breakpoints dbstep Execute one or more lines from current breakpoint dbstop Set breakpoints in M-file function dbtype List M-file with line numbers dbup Change local workspace context edit Edit or create M-file keyboard Invoke the keyboard in an M-file 1-5 1 Functions By Category Source Control checkin Check file into source control system checkout Check file out of source control system cmopts Get name of source control system customverctrlAllow custom source control system undocheckout Undo previous checkout from source control system Profiling profile Optimize performance of M-file code profreport Generate profile report System computer Identify information about computer on which MATLAB is running javachk Generate error message based on Java feature support license Show license number for MATLAB usejava Determine if a Java feature is supported in MATLAB ver Display version information for MathWorks products version Get MATLAB version number Performance Improvement Tools and Techniques memory Help for memory limitations pack Consolidate workspace memory profile Optimize performance of M-file code profreport Generate profile report rehash Refresh function and file system caches sparse Create sparse matrix zeros Create array of all zeros 1-6