您好,欢迎光临本网站![请登录][注册会员]  
文件名称: Matlab 7 - Programming.pdf
  所属分类: 其它
  开发工具:
  文件大小: 4mb
  下载次数: 0
  上传时间: 2009-06-11
  提 供 者: xiaoga******
 详细说明: 该书是系统介绍了MATLAB的所有function功能,可以说是一本programming大全,而且还是英文版,值得收藏,而且敝人还打印了一份,正在苦学之中…… Creating and Concatenating Matrices . . . . . . . . . . . . . . . . . . 1-3 Constructing a Simple Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Specialized Matrix Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Concatenating Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7 Matrix Concatenation Functions . . . . . . . . . . . . . . . . . . . . . . . . 1-8 Generating a Numeric Sequence . . . . . . . . . . . . . . . . . . . . . . . 1-10 Combining Unlike Data Types . . . . . . . . . . . . . . . . . . . . . . . . . 1-11 Accessing Elements of a Matrix . . . . . . . . . . . . . . . . . . . . . . . 1-14 Accessing Single Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14 Linear Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15 Functions That Control Indexing Style . . . . . . . . . . . . . . . . . . 1-16 Accessing Multiple Elements . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16 Logical Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-18 Getting Information About a Matrix . . . . . . . . . . . . . . . . . . . 1-19 Dimensions of the Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-19 Data Types Used in the Matrix . . . . . . . . . . . . . . . . . . . . . . . . 1-20 Data Structures Used in the Matrix . . . . . . . . . . . . . . . . . . . . 1-21 Resizing and Reshaping Matrices . . . . . . . . . . . . . . . . . . . . . 1-22 Expanding the Size of a Matrix . . . . . . . . . . . . . . . . . . . . . . . . 1-22 Diminishing the Size of a Matrix . . . . . . . . . . . . . . . . . . . . . . . 1-23 Reshaping a Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-24 Shifting and Sorting Matrices . . . . . . . . . . . . . . . . . . . . . . . . . 1-26 Shift and Sort Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-26 Shifting the Location of Matrix Elements . . . . . . . . . . . . . . . . 1-26 Sorting the Data in Each Column . . . . . . . . . . . . . . . . . . . . . . 1-28 Sorting the Data in Each Row . . . . . . . . . . . . . . . . . . . . . . . . . 1-28 Sorting Row Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-29 Operating on Diagonal Matrices . . . . . . . . . . . . . . . . . . . . . . . 1-30 Constructing a Matrix from a Diagonal Vector . . . . . . . . . . . . 1-30 Returning a Triangular Portion of a Matrix . . . . . . . . . . . . . . . 1-31 Concatenating Matrices Diagonally . . . . . . . . . . . . . . . . . . . . . 1-31 Empty Matrices, Scalars, and Vectors . . . . . . . . . . . . . . . . . . 1-32 The Empty Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-32 Scalars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-34 Full and Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-35 Sparse Matrix Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-35 Multidimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-37 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-37 Creating Multidimensional Arrays . . . . . . . . . . . . . . . . . . . . . . 1-39 Accessing Multidimensional Array Properties . . . . . . . . . . . . . 1-43 Indexing Multidimensional Arrays . . . . . . . . . . . . . . . . . . . . . . 1-43 Reshaping Multidimensional Arrays . . . . . . . . . . . . . . . . . . . . 1-47 Permuting Array Dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . 1-49 Computing with Multidimensional Arrays . . . . . . . . . . . . . . . . 1-51 Organizing Data in Multidimensional Arrays . . . . . . . . . . . . . 1-53 Multidimensional Cell Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . 1-55 Multidimensional Structure Arrays . . . . . . . . . . . . . . . . . . . . . 1-56 Summary of Matrix and Array Functions . . . . . . . . . . . . . . . 1-58 2 Data Types Overview of MATLAB Data Types . . . . . . . . . . . . . . . . . . . . . . 2-2 Numeric Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Floating-Point Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 Complex Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11 Infinity and NaN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12 iii Identifying Numeric Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14 Display Format for Numeric Values . . . . . . . . . . . . . . . . . . . . . 2-14 Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16 Logical Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20 Creating a Logical Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20 How Logical Arrays Are Used . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22 Identifying Logical Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24 Characters and Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-25 Creating Character Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-25 Cell Arrays of Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27 String Comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-29 Searching and Replacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-32 Converting from Numeric to String . . . . . . . . . . . . . . . . . . . . . 2-34 Converting from String to Numeric . . . . . . . . . . . . . . . . . . . . . 2-35 Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-37 Dates and Times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-41 Types of Date Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-41 Conversions Between Date Formats . . . . . . . . . . . . . . . . . . . . . 2-43 Date String Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-44 Output Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-44 Current Date and Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-46 Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-47 Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-49 Building Structure Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-50 Accessing Data in Structure Arrays . . . . . . . . . . . . . . . . . . . . . 2-53 Using Dynamic Field Names . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-54 Finding the Size of Structure Arrays . . . . . . . . . . . . . . . . . . . . 2-55 Adding Fields to Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-56 Deleting Fields from Structures . . . . . . . . . . . . . . . . . . . . . . . . 2-56 Applying Functions and Operators . . . . . . . . . . . . . . . . . . . . . . 2-56 Writing Functions to Operate on Structures . . . . . . . . . . . . . . 2-57 Organizing Data in Structure Arrays . . . . . . . . . . . . . . . . . . . . 2-59 Nesting Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-63 Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-65 iv Contents Cell Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-66 Creating Cell Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-67 Obtaining Data from Cell Arrays . . . . . . . . . . . . . . . . . . . . . . . 2-70 Deleting Cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-71 Reshaping Cell Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-72 Replacing Lists of Variables with Cell Arrays . . . . . . . . . . . . . 2-72 Applying Functions and Operators . . . . . . . . . . . . . . . . . . . . . . 2-74 Organizing Data in Cell Arrays . . . . . . . . . . . . . . . . . . . . . . . . 2-74 Nesting Cell Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-75 Converting Between Cell and Numeric Arrays . . . . . . . . . . . . 2-77 Cell Arrays of Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-78 Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-79 Function Handles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-80 Constructing and Invoking a Function Handle . . . . . . . . . . . . 2-80 Calling a Function Using Its Handle . . . . . . . . . . . . . . . . . . . . 2-80 Simple Function Handle Example . . . . . . . . . . . . . . . . . . . . . . 2-81 MATLAB Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-82 Java Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-83 3 Basic Program Components Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Types of Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Naming Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6 Guidelines to Using Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7 Scope of a Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7 Lifetime of a Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8 Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9 Special Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10 v Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12 Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12 Relational Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13 Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 Operator Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20 MATLAB Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-22 String Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-22 Shell Escape Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23 Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-25 MATLAB Regular Expression Functions . . . . . . . . . . . . . . . . . 3-25 Elements of an Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-26 Character Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-26 Character Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29 Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30 Lookaround Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-33 Quantifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-36 Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-40 Handling Multiple Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-46 Operator Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-49 Comma-Separated Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-54 Generating a List from a Cell Array . . . . . . . . . . . . . . . . . . . . . 3-54 Generating a List from a Structure . . . . . . . . . . . . . . . . . . . . . 3-55 How to Use the Comma-Separated List . . . . . . . . . . . . . . . . . . 3-56 Fast Fourier Transform Example . . . . . . . . . . . . . . . . . . . . . . . 3-58 Program Control Statements . . . . . . . . . . . . . . . . . . . . . . . . . . 3-60 Conditional Control — if, switch . . . . . . . . . . . . . . . . . . . . . . . . 3-60 Loop Control — for, while, continue, break . . . . . . . . . . . . . . . 3-64 Error Control — try, catch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-67 Program Termination — return . . . . . . . . . . . . . . . . . . . . . . . . 3-68 Symbol Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-69 Asterisk — * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-70 At — @ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-70 Colon — : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-71 Comma — , . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-72 vi Contents Curly Braces — { } . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-73 Dot — . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-73 Dot-Dot — .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-74 Dot-Dot-Dot (Ellipsis) — ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-74 Dot-Parentheses — .( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-75 Exclamation Point — ! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-75 Parentheses — ( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-76 Percent — % . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-76 Percent-Brace — %{ %} . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-77 Semicolon — ; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-77 Single Quotes — ' ' . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-78 Space Character . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-78 Slash and Backslash — / \ . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-79 Square Brackets — [ ] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-79 MATLAB Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-81 M-File Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-81 Built-In Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-82 Overloaded MATLAB Functions . . . . . . . . . . . . . . . . . . . . . . . . 3-83 4 M-File Programming Program Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 Creating a Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 Getting the Bugs Out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3 Cleaning Up the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4 Improving Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5 Checking It In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6 Working with M-Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7 Types of M-Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7 Basic Parts of an M-File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8 Creating a Simple M-File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13 Providing Help for Your Program . . . . . . . . . . . . . . . . . . . . . . . 4-15 Creating P-Code Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15 vii M-File Scripts and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16 M-File Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16 M-File Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-17 Types of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-18 Identifying Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-19 Function Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21 Checking the Number of Input Arguments . . . . . . . . . . . . . . . 4-21 Passing Variable Numbers of Arguments . . . . . . . . . . . . . . . . 4-23 Returning Output Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25 Function Handles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-27 Constructing a Function Handle . . . . . . . . . . . . . . . . . . . . . . . . 4-27 Calling a Function Using Its Handle . . . . . . . . . . . . . . . . . . . . 4-28 Functions That Operate on Function Handles . . . . . . . . . . . . . 4-29 Additional Information on Function Handles . . . . . . . . . . . . . 4-29 Calling Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-31 What Happens When You Call a Function . . . . . . . . . . . . . . . . 4-31 Determining Which Function Is Called . . . . . . . . . . . . . . . . . . 4-31 MATLAB Calling Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34 Passing Certain Argument Types . . . . . . . . . . . . . . . . . . . . . . . 4-37 Passing Arguments in Structures or Cell Arrays . . . . . . . . . . . 4-39 Calling External Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-40 5 Types of Functions Overview of MATLAB Function Types . . . . . . . . . . . . . . . . . . 5-2 Anonymous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3 Constructing an Anonymous Function . . . . . . . . . . . . . . . . . . . . 5-3 Arrays of Anonymous Functions . . . . . . . . . . . . . . . . . . . . . . . . . 5-5 Outputs from Anonymous Functions . . . . . . . . . . . . . . . . . . . . . 5-6 Variables Used in the Expression . . . . . . . . . . . . . . . . . . . . . . . . 5-8 Examples of Anonymous Functions . . . . . . . . . . . . . . . . . . . . . 5-11 viii Contents Primary M-File Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14 Nested Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15 Writing Nested Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15 Calling Nested Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17 Variable Scope in Nested Functions . . . . . . . . . . . . . . . . . . . . . 5-18 Using Function Handles with Nested Functions . . . . . . . . . . . 5-20 Examples of Nested Functions . . . . . . . . . . . . . . . . . . . . . . . . . 5-25 Subfunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-31 Calling Subfunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-32 Accessing Help for a Subfunction . . . . . . . . . . . . . . . . . . . . . . . 5-32 Private Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-33 Private Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-33 Accessing Help for a Private Function . . . . . . . . . . . . . . . . . . . 5-33 Overloaded Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-34 Class Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-34 6 Data Import and Export Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 Text Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 Graphics Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 Audio and Audio/Video Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 Spreadsheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 Scientific Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 The Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 Low-Level File I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5 Toolboxes for Importing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5 Using the Import Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6 Using the Import Wizard with Text Data . . . . . . . . . . . . . . . . . 6-6 Using the Import Wizard with Binary Data . . . . . . . . . . . . . . . 6-12 ix Supported File Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-15 Saving and Loading MAT-Files . . . . . . . . . . . . . . . . . . . . . . . . 6-17 Exporting Data to MAT-Files . . . . . . . . . . . . . . . . . . . . . . . . . . 6-17 Importing Data from MAT-Files . . . . . . . . . . . . . . . . . . . . . . . . 6-22 Importing Text Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-26 The MATLAB Import Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . 6-26 Using Import Functions with Text Data . . . . . . . . . . . . . . . . . 6-26 Importing Numeric Text Data . . . . . . . . . . . . . . . . . . . . . . . . . . 6-29 Importing Delimited ASCII Data Files . . . . . . . . . . . . . . . . . . . 6-30 Importing Numeric Data with Text Headers . . . . . . . . . . . . . . 6-30 Importing Mixed Alphabetic and Numeric Data . . . . . . . . . . . 6-31 Importing from XML Documents . . . . . . . . . . . . . . . . . . . . . . . 6-33 Exporting Text Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-34 Exporting Delimited ASCII Data Files . . . . . . . . . . . . . . . . . . . 6-35 Using the diary Function to Export Data . . . . . . . . . . . . . . . . . 6-37 Exporting to XML Documents . . . . . . . . . . . . . . . . . . . . . . . . . . 6-38 Working with Graphics Files . . . . . . . . . . . . . . . . . . . . . . . . . . 6-39 Getting Information About Graphics Files . . . . . . . . . . . . . . . . 6-39 Importing Graphics Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-40 Exporting Graphics Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-40 Working with Audio and Video Data . . . . . . . . . . . . . . . . . . . 6-42 Getting Information About Audio/Video Files . . . . . . . . . . . . . 6-42 Importing Audio/Video Data . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-43 Exporting Audio/Video Data . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-44 Working with Spreadsheets . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-46 Microsoft Excel Spreadsheets . . . . . . . . . . . . . . . . . . . . . . . . . . 6-46 Lotus 123 Spreadsheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-49 Working with Scientific Data Formats . . . . . . . . . . . . . . . . . 6-52 Working with Common Data Format (CDF) Files . . . . . . . . . . 6-52 Working with Flexible Image Transport System (FITS) Files 6-55 Working with Hierarchical Data Format (HDF5) Files . . . . . . 6-57 x Contents Importing HDF4 and HDF-EOS Data . . . . . . . . . . . . . . . . . . . 6-67 Using the HDF Import Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-67 Using the HDF4 Import Tool Subsetting Options . . . . . . . . . . 6-72 Using the MATLAB hdfread Function . . . . . . . . . . . . . . . . . . . 6-82 Using the HDF4 Command-Line Interface . . . . . . . . . . . . . . . 6-86 Exporting MATLAB Data to an HDF4 File . . . . . . . . . . . . . . 6-94 Example: Exporting Data to an HDF4 File . . . . . . . . . . . . . . . 6-94 Using the MATLAB HDF Utility API . . . . . . . . . . . . . . . . . . . 6-101 Using Low-Level File I/O Functions . . . . . . . . . . . . . . . . . . . 6-103 Opening Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-104 Reading Binary Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-106 Writing Binary Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-108 Controlling Position in a File . . . . . . . . . . . . . . . . . . . . . . . . . 6-108 Reading Strings Line by Line from Text Files . . . . . . . . . . . . 6-110 Reading Formatted ASCII Data . . . . . . . . . . . . . . . . . . . . . . . 6-112 Writing Formatted Text Files . . . . . . . . . . . . . . . . . . . . . . . . . 6-113 Closing a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-114 Exchanging Files over the Internet . . . . . . . . . . . . . . . . . . . 6-116 Downloading Web Content and Files . . . . . . . . . . . . . . . . . . . 6-116 Creating and Uncompressing Zip Archives . . . . . . . . . . . . . . 6-118 Sending E-Mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-119 Performing FTP File Operations . . . . . . . . . . . . . . . . . . . . . . . 6-121 7 Error Handling Checking for Errors with try-catch . . . . . . . . . . . . . . . . . . . . . 7-2 Nested try-catch Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3 Handling and Recovering from an Error . . . . . . . . . . . . . . . . 7-4 Reporting an Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4 Identifying the Cause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-5 Regenerating an Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7 xi Message Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8 Identifier Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8 Using Message Identifiers with lasterr . . . . . . . . . . . . . . . . . . . 7-9 Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-12 Reporting a Warning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-12 Identifying the Cause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-13 Warning Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14 Warning Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14 Warning Control Statements . . . . . . . . . . . . . . . . . . . . . . . . . . 7-15 Output from Control Statements . . . . . . . . . . . . . . . . . . . . . . . 7-17 Saving and Restoring State . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-20 Debug, Backtrace, and Verbose Modes . . . . . . . . . . . . . . . . . . . 7-21 Debugging Errors and Warnings . . . . . . . . . . . . . . . . . . . . . . 7-23 8 Classes and Objects Classes and Objects: An Overview . . . . . . . . . . . . . . . . . . . . . . 8-2 Features of Object-Oriented Programming . . . . . . . . . . . . . . . . 8-2 MATLAB Data Class Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . 8-3 Creating Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-4 Invoking Methods on Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-4 Private Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5 Helper Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5 Debugging Class Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5 Setting Up Class Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6 Data Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-7 Tips for C++ and Java Programmers . . . . . . . . . . . . . . . . . . . . . 8-7 Designing User Classes in MATLAB . . . . . . . . . . . . . . . . . . . . . 8-9 The MATLAB Canonical Class . . . . . . . . . . . . . . . . . . . . . . . . . . 8-9 The Class Constructor Method . . . . . . . . . . . . . . . . . . . . . . . . . 8-10 Examples of Constructor Methods . . . . . . . . . . . . . . . . . . . . . . 8-11 Identifying Objects Outside the Class Directory . . . . . . . . . . . 8-11 xii Contents The display Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-12 Accessing Object Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-13 The set and get Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-13 Indexed Reference Using subsref and subsasgn . . . . . . . . . . . 8-14 Handling Subscripted Reference . . . . . . . . . . . . . . . . . . . . . . . . 8-15 Handling Subscripted Assignment . . . . . . . . . . . . . . . . . . . . . . 8-17 Object Indexing Within Methods . . . . . . . . . . . . . . . . . . . . . . . 8-18 Defining end Indexing for an Object . . . . . . . . . . . . . . . . . . . . . 8-19 Indexing an Object with Another Object . . . . . . . . . . . . . . . . . 8-19 Converter Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-20 Overloading Operators and Functions . . . . . . . . . . . . . . . . . 8-21 Overloading Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-21 Overloading Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-23 Example — A Polynomial Class . . . . . . . . . . . . . . . . . . . . . . . . 8-24 Polynom Data Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-24 Polynom Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-24 The Polynom Constructor Method . . . . . . . . . . . . . . . . . . . . . . 8-24 Converter Methods for the Polynom Class . . . . . . . . . . . . . . . . 8-25 The Polynom display Method . . . . . . . . . . . . . . . . . . . . . . . . . . 8-28 The Polynom subsref Method . . . . . . . . . . . . . . . . . . . . . . . . . . 8-28 Overloading Arithmetic Operators for polynom . . . . . . . . . . . . 8-29 Overloading Functions for the Polynom Class . . . . . . . . . . . . . 8-31 Listing Class Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-33 Building on Other Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-35 Simple Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-35 Multiple Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-36 Aggregation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-37 Example — Assets and Asset Subclasses . . . . . . . . . . . . . . . . 8-38 Inheritance Model for the Asset Class . . . . . . . . . . . . . . . . . . . 8-38 Asset Class Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-39 Other Asset Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-39 The Asset Constructor Method . . . . . . . . . . . . . . . . . . . . . . . . . 8-39 The Asset get Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-41 The Asset set Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-41 The Asset subsref Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-42 The Asset subsasgn Method . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-43 xiii The Asset display Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-44 The Asset fieldcount Method . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-45 Designing the Stock Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-45 The Stock Constructor Method . . . . . . . . . . . . . . . . . . . . . . . . . 8-46 The Stock get Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-48 The Stock set Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-49 The Stock subsref Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-50 The Stock subsasgn Method . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-51 The Stock display Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-53 Example — The Portfolio Container . . . . . . . . . . . . . . . . . . . 8-54 Designing the Portfolio Class . . . . . . . . . . . . . . . . . . . . . . . . . . 8-54 The Portfolio Constructor Method . . . . . . . . . . . . . . . . . . . . . . 8-55 The Portfolio display Method . . . . . . . . . . . . . . . . . . . . . . . . . . 8-56 The Portfolio pie3 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-57 Creating a Portfolio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-58 Saving and Loading Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-60 Modifying Objects During Save or Load . . . . . . . . . . . . . . . . . . 8-60 Example — Defining saveobj and loadobj for Portfolio . . 8-61 Summary of Code Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-61 The saveobj Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-62 The loadobj Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-62 Changing the Portfolio Constructor . . . . . . . . . . . . . . . . . . . . . 8-63 The Portfolio subsref Method . . . . . . . . . . . . . . . . . . . . . . . . . . 8-64 Object Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-65 Specifying Precedence of User-Defined Classes . . . . . . . . . . . . 8-66 How MATLAB Determines Which Method to Call . . . . . . . 8-67 Selecting a Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-67 Querying Which Method MATLAB Will Call . . . . . . . . . . . . . . 8-70 ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: Matlab Programming 完美教材
 输入关键字,在本站1000多万海量源码库中尽情搜索: