Tài liệu MATLAB® 7 Programming: How to Contact The MathWorks - Pdf 86

MATLAB
®
7
Programming
How to Contact The MathWorks
www.mathworks.c
om
Web
comp.soft-sys.matlab
Newsgroup
www.mathworks.com/contact_TS.html
Technical Support
[email protected]
Product enhancement suggestions
[email protected]
om
Bug reports
[email protected]
Documentation error reports
[email protected]
Order status, license renewals, passcodes
[email protected]
om
Sales, pricing, an
d 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.

June 2005 Second printing Minor revision for MATLAB 7.0.4
September 2005 Online only Revised for MATLAB 7.1 (Release 14SP3)
March 2006 Online only Revised for MATLAB 7.2 (Release R2006a)
September 2006 Online only Revised for MATLAB 7.3 (Release R2006b)
March 2007 Online only Revised for MATLAB 7.4 (Release R2007a)

Contents
Data Structures
1
Creating and Concatenating Matrices
...............
1-3
Constructing a Simple Matrix
.......................
1-3
Specialized Matrix Functions
........................
1-5
Concatenating Matrices
............................
1-7
Matrix Concatenation Functions
.....................
1-8
Generating a Numeric Sequence
.....................
1-10
Combining Unlike Data Types
.......................
1-12

Data Structures Used in the Matrix
..................
1-26
Resizing and Reshaping Matrices
...................
1-27
Expanding the Size of a Matrix
......................
1-27
Diminishing the Size of a Matrix
.....................
1-31
Reshaping a Matrix
................................
1-32
Preallocating Memory
..............................
1-34
Shifting and Sorting Matrices
......................
1-37
Shift and Sort Functions
............................
1-37
Shifting the Location of Matrix Elements
..............
1-37
Sorting the Data in Each Column
....................
1-39

1-48
Full and Sparse Matrices
...........................
1-50
Sparse Matrix Functions
...........................
1-50
Multidimensional Arrays
...........................
1-52
Overview
........................................
1-52
Creating Multidimensional Arrays
...................
1-54
Accessing Multidimensional Array Properties
..........
1-57
Indexing Multidimensional Arrays
...................
1-58
Reshaping Multidimensional Arrays
..................
1-62
Permuting Array Dimensions
........................
1-64
Computing with Multidimensional Arrays
.............

Complex Numbers
.................................
2-24
Infinity and NaN
..................................
2-25
vi
Contents
Identifying Numeric Types
..........................
2-27
Display Format for Numeric Values
...................
2-27
Function Summary
................................
2-29
Logical Types
.....................................
2-33
Creating a Logical Array
...........................
2-33
How Logical Arrays Are Used
.......................
2-35
Identifying Logical Arrays
..........................
2-37
Characters and Strings

.............................
2-67
Conversions Between Date Formats
..................
2-69
Date String Formats
...............................
2-69
Output Formats
...................................
2-70
Current Date and Time
.............................
2-72
Function Summary
................................
2-72
Structures
........................................
2-75
Building Structure Arrays
..........................
2-76
Accessing Data in Structure Arrays
...................
2-79
Using Dynamic Field Names
........................
2-81
Finding the Size of Structure Arrays

Creating a Cell Array
..............................
2-96
Referencing Cells of a Cell Array
.....................
2-100
Deleting Cells
....................................
2-107
Reshaping Cell Arrays
.............................
2-107
Replacing Lists of Variables with Cell Arrays
...........
2-108
Applying Functions and Operators
...................
2-109
Organizing Data in Cell Arrays
......................
2-110
Nesting Cell Arrays
................................
2-111
Converting Between Cell and Numeric Arrays
..........
2-113
Cell Arrays of Structures
...........................
2-114

.................................
3-7
Guidelines to Using Variables
.......................
3-11
Scope of a Variable
................................
3-11
Lifetime of a Variable
..............................
3-13
Keywords
.........................................
3-14
Special Values
.....................................
3-15
Operators
.........................................
3-17
Arithmetic Operators
..............................
3-17
Relational Operators
...............................
3-18
viii
Contents
Logical Operators
.................................

3-37
Nonmatching Operators
............................
3-39
Positional Operators
...............................
3-40
Lookaround Operators
.............................
3-41
Quantifiers
.......................................
3-45
Tokens
..........................................
3-48
Named Capture
...................................
3-53
Conditional Expressions
............................
3-55
Dynamic Regular Expressions
.......................
3-58
String Replacement
................................
3-67
Handling Multiple Strings
..........................

3-92
Error Control — try, catch
..........................
3-95
Program Termination — return
......................
3-96
Symbol Reference
.................................
3-97
Asterisk — *
.....................................
3-98
At — @
..........................................
3-98
Colon — :
........................................
3-99
ix
Comma — ,
......................................
3-100
Curly Braces — { }
.................................
3-101
Dot — .
..........................................
3-102
Dot-Dot — ..

..........................
3-108
Square Brackets — [ ]
..............................
3-108
MATLAB Functions
................................
3-110
M-File Functions
..................................
3-110
Built-In Functions
.................................
3-111
Overloaded MATLAB Functions
.....................
3-112
M-File Programming
4
Program D
evelopment
.............................
4-3
Creatin
gaProgram
................................
4-3
Getting
the Bugs Out
..............................

iding Help for Your Program
.....................
4-16
Crea
ting P-Code Files
..............................
4-16
M-F
ile Scripts and Functions
.......................
4-1
8
x
Contents
M-File Scripts
....................................
4-18
M-File Functions
..................................
4-19
Types of Functions
................................
4-20
Identifying Dependencies
...........................
4-21
Function Handles
..................................
4-23
Constructing a Function Handle

.................
4-51
Calling Functions
..................................
4-53
What Happens When You Call a Function
.............
4-53
Determining Which Function Is Called
................
4-54
MATLAB Calling Syntax
...........................
4-57
Passing Certain Argument Types
....................
4-61
Passing Arguments in Structures or Cell Arrays
........
4-63
Assigning Output Arguments
........................
4-65
Calling External Functions
.........................
4-67
Running External Programs
........................
4-68
Types of Functions

..........................
5-15
Nested Functions
..................................
5-16
Writing Nested Functions
...........................
5-16
Calling Nested Functions
...........................
5-17
Variable Scope in Nested Functions
...................
5-19
Using Function Handles with Nested Functions
........
5-21
Restrictions on Assigning to Variables
................
5-26
Examples of Nested Functions
.......................
5-27
Subfunctions
......................................
5-33
Calling Subfunctions
...............................
5-34
Accessing Help for a Subfunction

6-5
Functi
ons Used in File Management
..................
6-7
Using
the Import Wizard
...........................
6-9
Start
ing the Import Wizard
.........................
6-9
Prev
iewing Contents of the File or Clipboard [Text only]
..
6-11
Spec
ifying Delimiters and Header Format [Text only]
....
6-12
Dete
rmining Assignment to Variables
.................
6-13
Auto
mated M-Code Generation
......................
6-16
Wri

Reading a Mapped File
.............................
6-54
Writing to a Mapped File
...........................
6-59
Methods of the memmapfile Class
....................
6-67
Deleting a Memory Map
............................
6-69
Memory-Mapping Demo
............................
6-69
Importing Text Data
...............................
6-75
The MATLAB Import Wizard
........................
6-75
Using Import Functions with Text Data
...............
6-75
Importing Numeric Text Data
.......................
6-78
Importing Delimited ASCII Data Files
................
6-79

Exporting Graphics Data
...........................
6-90
Working with Audio and Video Data
.................
6-92
Getting Information About Audio/Video Files
...........
6-92
Importing Audio/Video Data
.........................
6-93
Exporting Audio/Video Data
.........................
6-94
Working with Spreadsheets
.........................
6-97
xiii
Microsoft Excel Spreadsheets
........................
6-97
Lotus 123 Spreadsheets
............................
6-100
Using Low-Level File I/O Functions
.................
6-103
Opening Files
.....................................

6-118
Sending E-Mail
...................................
6-119
Performing FTP File Operations
.....................
6-121
Working with Scientific Data Formats
7
Common Da
ta Format (CDF) Files
...................
7-2
Getting I
nformation About CDF Files
.................
7-2
Importi
ng Data from a CDF File
.....................
7-3
Exporti
ng Data to a CDF File
.......................
7-6
Flexib
le Image Transport System (FITS) Files
........
7-8
Gettin

7-4
0
xiv
Contents
Using the MATLAB HDF4 High-Level Functions
.......
7-52
Using the HDF4 Low-Level Functions
................
7-55
Error Handling
8
Checking for Errors with try-catch
..................
8-2
Nested try-catch Blocks
............................
8-3
Handling and Recovering from an Error
.............
8-4
Reporting an Error
................................
8-4
Identifying the Cause
..............................
8-5
Regenerating an Error
.............................
8-8

Saving and Restoring State
.........................
8-22
Backtrace and Verbose Modes
.......................
8-23
Debugging Errors and Warnings
....................
8-26
Classes and Objects
9
Classes and Objects: An Overview
...................
9-2
xv
Features of Object-Oriented Programming
.............
9-3
MATLAB Data Class Hierarchy
......................
9-3
Creating Objects
..................................
9-4
Invoking Methods on Objects
........................
9-4
Private Methods
..................................
9-5

The display Method
................................
9-13
Accessing Object Data
..............................
9-13
The set and get Methods
............................
9-14
Indexed Reference Using subsref and subsasgn
.........
9-15
Handling Subscripted Reference
.....................
9-16
Handling Subscripted Assignment
....................
9-19
Object Indexing Within Methods
.....................
9-20
Defining end Indexing for an Object
..................
9-20
Indexing an Object with Another Object
...............
9-21
Converter Methods
................................
9-22

Overloading Arithmetic Operators for polynom
.........
9-32
Overloading Functions for the Polynom Class
..........
9-34
Listing Class Methods
.............................
9-36
xvi
Contents
Building on Other Classes
..........................
9-38
Simple Inheritance
................................
9-38
Multiple Inheritance
...............................
9-40
Aggregation
......................................
9-40
Example — Assets and Asset Subclasses
.............
9-41
Inheritance Model for the Asset Class
.................
9-42
Asset Class Design

.......................
9-50
The Stock get Method
..............................
9-52
The Stock set Method
..............................
9-53
The Stock subsref Method
..........................
9-54
The Stock subsasgn Method
.........................
9-55
The Stock display Method
...........................
9-57
Example — The Portfolio Container
.................
9-58
Designing the Portfolio Class
........................
9-58
The Portfolio Constructor Method
....................
9-59
The Portfolio display Method
........................
9-60
The Portfolio pie3 Method

xvii
Object Precedence
.................................
9-70
Specifying Precedence of User-Defined Classes
.........
9-70
How MATLAB Determines Which Method to Call
.....
9-72
Selecting a Method
................................
9-72
Querying Which Method MATLAB Will Call
...........
9-75
Scheduling Program Execution with Timers
10
Using a MATLAB Timer Object
......................
10-3
Example: Displaying a Message
.....................
10-4
Creating Timer Objects
............................
10-5
Timer Object Naming
..............................
10-6

Creating Callback Functions
........................
10-15
Specifying the Value of Callback Function Properties
....
10-17
Timer Object Execution Modes
......................
10-19
Executing a Timer Callback Function Once
............
10-19
Executing a Timer Callback Function Multiple Times
....
10-20
Handling Callback Function Queuing Conflicts
.........
10-21
Deleting Timer Objects from Memory
...............
10-23
xviii
Contents
Testing the Validity of a Timer Object
.................
10-23
Deleting All Existing Timer Objects
..................
10-23
Finding All Timer Objects in Memory

11-4
Preallocat
ing Arrays
...............................
11-7
Coding Loop
sinaMEX-File
.........................
11-9
Assigning
to Variables
.............................
11-9
Operating
on Real Data
............................
11-10
Using Appr
opriate Logical Operators
.................
11-10
Overload
ing Built-In Functions
......................
11-11
Function
s Are Generally Faster Than Scripts
...........
11-11
Load and S

11-21
Gener
al Suggestions for Reclaiming Memory
...........
11-21
Comp
ressing Data in Memory
.......................
11-2
2
Incr
easing System Swap Space
......................
11-2
2
Free
ing Up System Resources on Windows Systems
.....
11-2
3
Relo
ading Variables on UNIX Systems
................
11-2
3
xix
Programming Tips
12
Command and Function Syntax
.....................

12-7
Help on Functions from the Command Window
.........
12-7
Topical Help
......................................
12-7
Paged Output
.....................................
12-8
Writing Your Own Help
............................
12-9
Help for Subfunctions and Private Functions
...........
12-9
Help for Methods and Overloaded Functions
...........
12-9
Development Environment
.........................
12-11
Workspace Browser
................................
12-11
Using the Find and Replace Utility
...................
12-11
Commenting Out a Block of Code
....................

12-16
Variable Numbers of Arguments
.....................
12-16
String or Numeric Arguments
.......................
12-17
Passing Arguments in a Structure
....................
12-17
xx
Contents
Passing Arguments in a Cell Array
...................
12-18
Program Development
.............................
12-19
Planning the Program
..............................
12-19
Using Pseudo-Code
................................
12-19
Selecting the Right Data Structures
..................
12-19
General Coding Practices
...........................
12-20

A Quick Way to Examine Variables
...................
12-23
Setting Breakpoints from the Command Line
..........
12-24
Finding Line Numbers to Set Breakpoints
.............
12-24
Stopping Execution on an Error or Warning
............
12-24
Locating an Error from the Error Message
.............
12-24
Using Warnings to Help Debug
......................
12-25
Making Code Execution Visible
......................
12-25
Debugging Scripts
.................................
12-25
Variables
..........................................
12-26
Rules for Variable Names
...........................
12-26

Comparing Methods of Concatenation
.................
12-30
Store Arrays of Strings in a Cell Array
................
12-31
xxi
Converting Between Strings and Cell Arrays
...........
12-31
Search and Replace Using Regular Expressions
.........
12-31
Evaluating Expressions
............................
12-33
Find Alternatives to Using eval
......................
12-33
Assigning to a Series of Variables
....................
12-33
Short-Circuit Logical Operators
......................
12-33
Changing the Counter Variable within a for Loop
.......
12-34
MATLAB Path
.....................................

12-40
MATLAB case Evaluates Strings
.....................
12-40
Multiple Conditions in a case Statement
...............
12-40
Implicit Break in switch-case
........................
12-40
Variable Scope in a switch
..........................
12-41
Catching Errors with try-catch
......................
12-41
Nested try-catch Blocks
............................
12-42
Forcing an Early Return from a Function
..............
12-42
Save and Load
.....................................
12-43
Saving Data from the Workspace
.....................
12-43
Loading Data into the Workspace
....................

Determining Filenames at Run-Time
.................
12-47
Returning the Size of a File
.........................
12-47
Input/Output
......................................
12-49
File I/O Function Overview
.........................
12-49
Common I/O Functions
.............................
12-49
Readable File Formats
.............................
12-50
Using the Import Wizard
...........................
12-50
Loading Mixed Format Data
........................
12-50
Reading Files with Different Formats
.................
12-51
Reading ASCII Data into a Cell Array
.................
12-51

Demos Available with MATLAB
.....................
12-55
For More Information
..............................
12-56
Current CSSM
....................................
12-56
Archived CSSM
...................................
12-56
MATLAB Technical Support
.........................
12-56
Tech Notes
.......................................
12-56
MATLAB Central
.................................
12-56
MATLAB Newsletters (Digest, News & Notes)
..........
12-56
MATLAB Documentation
...........................
12-56
MATLAB Index of Examples
........................
12-56

Create a matrix or construct one
from other matrices.
Matrix Indexing (p. 1-18)
Access or assign to elements of a
matrix using methods of row and
column indexing.
Getting Information About a Matrix
(p. 1-24)
Retrieve information about the
structure or contents of a matrix.
Resizing and Reshaping Matrices
(p. 1-27)
Change the size, shape, or
arrangement of elements in an
existing matrix.
Shifting and Sorting Matrices
(p. 1-37)
Shift matrix elements along one or
more dimensions, or sort them into
an ascending or descending order.
Operating on Diagonal Matrices
(p. 1-42)
Construct and manipulate matrices
along a diagonal of the rectangular
shape.


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status