【实例简介】Matlab Primer
【实例截图】
【核心代码】
Quick Start
1
MATLAB Product Description ........................... 1-2
Key Features ..................................... 1-2
Desktop Basics ....................................... 1-3
Matrices and Arrays .................................. 1-5
Array Indexing ...................................... 1-10
Workspace Variables ................................. 1-12
Text and Characters .................................. 1-13
Text in String Arrays ............................... 1-13
Data in Character Arrays ........................... 1-14
Calling Functions .................................... 1-15
2-D and 3-D Plots .................................... 1-17
Programming and Scripts ............................. 1-24
Scripts ......................................... 1-24
Live Scripts ..................................... 1-25
Loops and Conditional Statements .................... 1-26
Script Locations .................................. 1-27
Help and Documentation ............................. 1-28
v
Contents
Language Fundamentals
2
Matrices and Magic Squares ........................... 2-2
About Matrices .................................... 2-2
Entering Matrices .................................. 2-4
sum, transpose, and diag ............................ 2-5
The magic Function ................................ 2-7
Generating Matrices ................................ 2-8
Expressions ......................................... 2-9
Variables ........................................ 2-9
Numbers ....................................... 2-10
Matrix Operators ................................. 2-11
Array Operators .................................. 2-11
Functions ....................................... 2-13
Examples of Expressions ........................... 2-14
Entering Commands ................................. 2-16
The format Function ............................... 2-16
Suppressing Output ............................... 2-17
Entering Long Statements .......................... 2-17
Command Line Editing ............................. 2-18
Indexing ........................................... 2-19
Subscripts ...................................... 2-19
The Colon Operator ............................... 2-20
Concatenation ................................... 2-21
Deleting Rows and Columns ......................... 2-22
Scalar Expansion ................................. 2-23
Logical Subscripting ............................... 2-23
The find Function ................................. 2-24
Types of Arrays ...................................... 2-26
Multidimensional Arrays ............................ 2-26
Cell Arrays ...................................... 2-28
Characters and Text ............................... 2-30
Structures ...................................... 2-33
vi Contents
Mathematics
3
Linear Algebra ....................................... 3-2
Matrices in the MATLAB Environment .................. 3-2
Systems of Linear Equations ......................... 3-13
Factorizations .................................... 3-25
Powers and Exponentials ........................... 3-32
Eigenvalues ..................................... 3-35
Singular Values .................................. 3-39
Operations on Nonlinear Functions ..................... 3-44
Function Handles ................................. 3-44
Function Functions ................................ 3-44
Multivariate Data .................................... 3-48
Data Analysis ....................................... 3-49
Introduction ..................................... 3-49
Preprocessing Data ............................... 3-49
Summarizing Data ................................ 3-55
Visualizing Data .................................. 3-59
Modeling Data ................................... 3-70
Graphics
4
Basic Plotting Functions ............................... 4-2
Creating a Plot .................................... 4-2
Plotting Multiple Data Sets in One Graph ................ 4-4
Specifying Line Styles and Colors ...................... 4-6
Plotting Lines and Markers ........................... 4-7
Graphing Imaginary and Complex Data .................. 4-9
Adding Plots to an Existing Graph ..................... 4-10
Figure Windows .................................. 4-12
Displaying Multiple Plots in One Figure ................ 4-12
Controlling the Axes ............................... 4-13
Adding Axis Labels and Titles ........................ 4-15
Saving Figures ................................... 4-16
Saving Workspace Data ............................ 4-17
vii
Creating Mesh and Surface Plots ....................... 4-19
About Mesh and Surface Plots ....................... 4-19
Visualizing Functions of Two Variables ................. 4-19
Display Images ...................................... 4-25
Image Data ...................................... 4-25
Reading and Writing Images ......................... 4-27
Printing Graphics ................................... 4-28
Overview of Printing ............................... 4-28
Printing from the File Menu ......................... 4-28
Exporting the Figure to a Graphics File ................ 4-28
Using the Print Command ........................... 4-29
Working with Graphics Objects ........................ 4-30
Graphics Objects ................................. 4-30
Setting Object Properties ........................... 4-33
Functions for Working with Objects ................... 4-35
Passing Arguments ................................ 4-36
Finding the Handles of Existing Objects ................ 4-37
Programming
5
Control Flow ......................................... 5-2
Conditional Control — if, else, switch ................... 5-2
Loop Control — for, while, continue, break ............... 5-5
Program Termination — return ........................ 5-7
Vectorization ..................................... 5-7
Preallocation ..................................... 5-8
Scripts and Functions ................................. 5-9
Overview ........................................ 5-9
Scripts ......................................... 5-10
Functions ....................................... 5-11
Types of Functions ................................ 5-13
Global Variables .................................. 5-15
Command vs. Function Syntax ....................... 5-15
viii Contents