Language Reference Manual
Total Page:16
File Type:pdf, Size:1020Kb
MATLAB The Language5 of Technical Computing Computation Visualization Programming Language Reference Manual Version 5 How to Contact The MathWorks: ☎ (508) 647-7000 Phone PHONE (508) 647-7001 Fax FAX ☎ (508) 647-7022 Technical Support Faxback Server FAX SERVER ✉ MAIL The MathWorks, Inc. Mail 24 Prime Park Way Natick, MA 01760-1500 http://www.mathworks.com Web INTERNET ftp.mathworks.com Anonymous FTP server @ [email protected] Technical support E-MAIL [email protected] Product enhancement suggestions [email protected] Bug reports [email protected] Documentation error reports [email protected] Subscribing user registration [email protected] Order status, license renewals, passcodes [email protected] Sales, pricing, and general information Language Reference Manual (November 1996) COPYRIGHT 1994 - 1996 by The MathWorks, Inc. All Rights Reserved. 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 repro- duced in any form without prior written consent from The MathWorks, Inc. U.S. GOVERNMENT: If Licensee is acquiring the software on behalf of any unit or agency of the U. S. Government, the following shall apply: (a) for units of the Department of Defense: RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the Government is subject to restric- tions as set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software Clause at DFARS 252.227-7013. (b) for any other unit or agency: NOTICE - Notwithstanding any other lease or license agreement that may pertain to, or accompany the delivery of, the computer software and accompanying documentation, the rights of the Government regarding its use, reproduction and disclosure are as set forth in Clause 52.227-19(c)(2) of the FAR. Contractor/manufacturer is The MathWorks Inc., 24 Prime Park Way, Natick, MA 01760-1500. MATLAB, SIMULINK, and Handle Graphics are registered trademarks and Real-Time Workshop is a trade- mark of The MathWorks, Inc. Other product or brand names are trademarks or registered trademarks of their respective holders. Preface iii Preface What Is MATLAB? MATLAB is a technical computing environment for high-performance numeric computation and visualization. MATLAB integrates numerical anal- ysis, matrix computation, signal processing, and graphics in an easy-to-use environment where problems and solutions are expressed just as they are written mathematically – without traditional programming. The name MATLAB stands for matrix laboratory. MATLAB was originally written to provide easy access to matrix software developed by the LINPACK and EISPACK projects, which together represent the state of the art in soft- ware for matrix computation. MATLAB is an interactive system whose basic data element is an array that does not require dimensioning. This allows you to solve many numerical prob- lems in a fraction of the time it would take to write a program in a language such as Fortran, Basic, or C. MATLAB has evolved over a period of years with input from many users. In uni- versity environments, it has become the standard instructional tool for intro- ductory courses in applied linear algebra, as well as advanced courses in other areas. In industrial settings, MATLAB is used for research and to solve prac- tical engineering and mathematical problems. Typical uses include general purpose numeric computation, algorithm prototyping, and special purpose problem solving with matrix formulations that arise in disciplines such as automatic control theory, statistics, and digital signal processing (time-series analysis). MATLAB also features a family of application-specific solutions that we call toolboxes. Very important to most users of MATLAB, toolboxes are comprehen- sive collections of MATLAB functions (M-files) that extend the MATLAB envi- ronment in order to solve particular classes of problems. Areas in which toolboxes are available include signal processing, control systems design, dynamic systems simulation, systems identification, neural networks, and others. Probably the most important feature of MATLAB, and one that we took care to perfect, is its easy extensibility. This allows you to become a contributing author too, creating your own applications. In the years that MATLAB has been available, we have enjoyed watching many scientists, mathematicians, and engineers develop new and interesting applications, all without writing a single line of Fortran or other low-level code. iv What Is MATLAB? Who Wrote MATLAB? The original MATLAB was written in Fortran by Cleve Moler, in an evolu- tionary process over several years. The underlying matrix algorithms are from the many people who worked on the LINPACK and EISPACK projects. The current MATLAB program was written in C by The MathWorks. The first release was written by Steve Bangert, who wrote the parser/interpreter, Steve Kleiman, who implemented the graphics, and John Little and Cleve Moler, who wrote the analytical routines, the user's guide, and most of the M-files. Since the first release, many other people have joined the MATLAB development team and have made substantial contributions. v Preface MATLAB Documentation MATLAB comes with an extensive set of both online and printed documenta- tion. The online MATLAB Function Reference is a compendium of all MATLAB language and graphics commands plus mathematical functions. You can access this documentation from the MATLAB Help Desk. Users on all platforms can access this facility via the doc command.Windows and Macintosh users can additionally access this facility via the Help menu or the ? icon on the Com- mand Window toolbar. From the Help Desk main menu, choose “MATLAB Functions ” to display the Function Reference. The online documentation is augmented with a full set of printed documents, consisting of the following titles: • Getting Started with MATLAB , which explains how to get started with the fundamentals of MATLAB. • Using MATLAB, which explains how to use MATLAB as both a program- ming language and a command-line application. • MATLAB Graphics , which describes how to use MATLAB’s graphics and visualization tools. • MATLAB Application Program Interface Guide , which explains how to write C or Fortran programs that interact with MATLAB. • MATLAB 5 New Features Guide , which provides information useful in making the transition from MATLAB 4 to MATLAB 5. • MATLAB Installation Guide , which decribes how to install MATLAB on your platform. If one or more of the printed documents is unavailable to you, you can locate an online version of the same document via the Help Desk. vi Contents Preface What Is MATLAB? . iv MATLAB Documentation . vi Command Summary 1 General Purpose Commands . 1-2 Operators and Special Characters . 1-3 Logical Functions . 1-4 Language Constructs and Debugging . 1-4 Elementary Matrices and Matrix Manipulation . 1-5 Specialized Matrices . 1-7 Elementary Math Functions . 1-7 Specialized Math Functions . 1-8 Coordinate System Conversion . 1-8 Matrix Functions - Numerical Linear Algebra . 1-9 Data Analysis and Fourier Transform Functions . 1-10 Polynomial and Interpolation Functions . 1-11 i Function Functions – Nonlinear Numerical Methods . 1-12 Sparse Matrix Functions . 1-12 Sound Processing Functions . 1-14 Character String Functions . 1-14 Low-Level File I/O Functions . 1-15 Bitwise Functions . 1-16 Structure Functions . 1-17 Object Functions . 1-17 Cell Array Functions . 1-17 Multidimensional Array Functions . 1-17 Graphics Functions . 1-18 Reference 2 List of Commands Function Names . A–2 ii Contents 1 Command Summary This chapter lists MATLAB commands by functional area. 1 Command Summary General Purpose Commands Managing Commands and Functions addpath Add directories to MATLAB’s search path . page 2-23 doc Load hypertext documentation . page 2-194 help Online help for MATLAB functions and M-files . page 2-337 lasterr Last error message. page 2-394 lookfor Keyword search through all help entries. page 2-411 path Control MATLAB’s directory search path . page 2-490 profile Measure and display M-file execution profiles. page 2-520 rmpath Remove directories from MATLAB’s search path . page 2-556 type List file . page 2-664 version MATLAB version number . page 2-672 what Directory listing of M-files, MAT-files, and MEX-files . page 2-680 whatsnew Display README files for MATLAB and toolboxes . page 2-681 which Locate functions and files. page 2-682 Managing Variables and the Workspace clear Remove items from memory . page 2-108 disp Display text or array . page 2-190 length Length of vector. page 2-399 load Retrieve variables from disk . page 2-402 pack Consolidate workspace memory . page 2-486 save Save workspace variables on disk. page 2-565 size Array dimensions . page 2-580 who, whos List directory of variables in memory . page 2-685 Controlling the Command Window echo Echo M-files during execution. page 2-197 format Control the output display format . page 2-267 more Control paged output for the command window . page 2-435 Working with Files and the Operating Environment applescript Load a compiled AppleScript from a file and execute it . page 2-32 cd Change working directory . page 2-85 delete Delete files and graphics objects . page 2-183 diary Save session in a disk file . page 2-186 dir Directory listing. page 2-189 edit Edit an M-file. page 2-198 1-2 Operators and Special Characters fullfile Build full filename from parts . page 2-283 inmem Functions in memory . page 2-362 matlabroot Root directory of MATLAB installation . page 2-427 tempdir Return the name of the system’s temporary directory. page 2-654 tempname Unique name for temporary file . page 2-655 ! Execute operating system command . page 2-13 Starting and Quitting MATLAB matlabrc MATLAB startup M-file . page 2-426 quit Terminate MATLAB . page 2-533 startup MATLAB startup M-file . page 2-619 Operators and Special Characters + Plus .