contents 2.1 simple math 5 2.2 thematlabworkspace 7 2.3 about variables 8 v preface xvii 1 getting...

12
Contents 2 .1 SimpleMath5 2 .2 The MATLAB Workspace 7 2 .3 AboutVariables 8 v PREFACE xvii 1 GETTINGSTARTED 1 1 .1 Introduction1 1 .2 TypographicalConventions 2 1 .3 What'sNewin MATLAB6 2 1 .4 What'sin Mastering MATLAB 63 2 BASICFEATURES 5

Upload: votuong

Post on 20-May-2018

216 views

Category:

Documents


1 download

TRANSCRIPT

Contents

2.1

Simple Math 5

2.2

The MATLAB Workspace 7

2.3

About Variables 8

v

PREFACE xvii

1 GETTING STARTED 11.1 Introduction 1

1.2 Typographical Conventions 2

1.3 What's New in MATLAB 6 2

1.4 What's in Mastering MATLAB 6 3

2 BASIC FEATURES 5

vi

2.4

Comments, Punctuation, and Aborting Execution 10

2.5

Complex Numbers 12

2.6

Floating-Point Arithmetic 14

2.7

Mathematical Functions 15

3 THE MATLAB DESKTOP

Contents

21

5.1 Simple Arrays 37

5.2 Array Addressing or Indexing 38

5.3 Array Construction 40

5.4 Array Orientation 43

5.5 Scalar-Array Mathematics 46

5.6 Array-Array Mathematics 47

5.7 Standard Arrays 52

5.8 Array Manipulation 56

5.9 Array Sorting 67

5.10 Subarray Searching 69

5.11 Array Manipulation Functions 74

5.12 Array Size 78

5.13 Arrays and Memory Utilization 80

3.2

Managing the MATLAB Workspace 22

3.3

Memory Management 25

3.4

Number Display Formats

3.5

Keeping a Session Log

25

26

28

3 .6

3.7

System Information 27

The MATLAB Search Path

4 SCRIPT M-FILES 31

4.1 Script M-file Use 31

4.2 Startup and Finish 35

5 ARRAYS AND ARRAY OPERATIONS 37

Contents vii

6

7

MULTIDIMENSIONAL ARRAYS

89

85

6.1

6.2

6.3

Array Construction 86

Array Mathematics and Manipulation

Array Size 97

CELL ARRAYS AND STRUCTURES

1017 .1 Cell Array Creation 102

7.2 Cell Array Manipulation 105

7.3 Retrieving Cell Array Contents 107

7.4 Comma-Separated Lists 109

7.5 Cell Functions 112

7.6 Cell Arrays of Strings 114

7.7 Structure Creation 115

7.8 Structure Manipulation 119

7.9 Retrieving Structure Content 121

7.10 Comma-Separated Lists (Again) 122

7.11 Structure Functions 125

8 CHARACTER STRINGS 1298.1 String Construction 129

8.2 Numbers to Strings to Numbers 134

8.3 String Evaluation 140

8.4 String Functions 143

8.5 Cell Arrays of Strings 146

9 RELATIONAL AND LOGICAL OPERATIONS

151

9.1 Relational Operators 152

9.2 Logical Operators 155

9.3 Operator Precedence 156

9.4 Relational and Logical Functions 157

9.5 N a Ns and Empty Arrays 159

vw

10 CONTROL FLOW10.1

For Loops 163

10.2 While Loops 167

10.3

If-Else-End Constructions 168

10.4

Switch-Case Constructions 171

10.5 Try-Catch Blocks 172

11 FUNCTION M-FILES

Contents

163

175

11 .1

M-file Construction Rules

11 .2 Input and Output Arguments

11 .3

Function Workspaces 181

176

178

11 .4 Functions and the MATLAB Search Path 186

11 .5 Creating Your Own Toolbox

11.6 Command-Function Duality

188

189

11.7

Function Evaluation Using f e v a 1 190

12 M-FILE DEBUGGING AND PROFILING 19512.1 Debugging Tools 195

12.2 File Dependencies 197

12.3 Profiling M-files 199

13 FILE AND DIRECTORY MANAGEMENT 20313.1 Native Data Files 203

13 .2 Data Import and Export 206

13.3 Low-Level File UO 208

13.4 Directory Management 209

14 SET, BIT, AND BASE FUNCTIONS 21514.1 Set Functions 215

14.2 Bit Functions 219

14.3 Base Conversions 220

Contents

15 TIME COMPUTATIONS15 .1

Current Date and Time 221

15 .2 Date Format Conversions 222

15.3

Date Functions 225

15 .4 Timing Functions 226

15.5

Plot Labels 227

16 MATRIX ALGEBRA16.1

Sets of Linear Equations 232

16.2 Matrix Functions 235

16.3

Special Matrices 237

16.4 Sparse Matrices 238

16.5 Sparse Matrix Functions 240

17 DATA ANALYSIS17.1

Basic Statistical Analysis 244

17.2 Basic Data Analysis 253

17.3

Data Analysis and Statistical Functions 257

18 DATA INTERPOLATION18.1 One-Dimensional Interpolation 259

18.2 Two-Dimensional Interpolation 264

18.3 Triangulation and Scattered Data 268

18.4 Summary 273

19 POLYNOMIALS19 .1

Roots 275

19.2

Multiplication 276

19.3

Addition 276

19.4

Division 278

19.5

Derivatives and Integrals 278

ix

221

231

243

259

275

x

19.6 Evaluation 279

19 .7 Rational Polynomials

19.8

Curve Fitting 281

279

20 CUBIC SPLINES

Contents

285

289

295

20.2 Piecewise Polynomials 286

20.3 Cubic Hermite Polynomials

20.4

Integration 291

20.5 Differentiation 293

20.6 Spline Interpolation an a Plane

21 FOURIER ANALYSIS 299

21 .1 Discrete Fourier Transform 300

21 .2 Fourier Series 303

22 OPTIMIZATION 30922.1

Zero Finding 310

31422.2 Minimization in One Dimension

22.3 Minimization in Higher Dimensions 316

23

22.4

Practical Issues 319

321INTEGRATION AND DIFFERENTIATION

24

23 .1

Integration 321

23.2 Differentiation 326

333DIFFERENTIAL EQUATIONS24.1 IVP Format 334

24.2 ODE Suite Solvers 334

24.3 Basic Use 336

24.4 Setting Options 340

24.5 BVPs and PDEs 346

Contents

25 TWO-DIMENSIONAL GRAPHICS

26 THREE-DIMENSIONAL GRAPHICS

xi

349

38126.1 Line Plots 381

26.2 Scalar Functions of Two Variables 384

26.3 Mesh Plots 387

26.4 Surface Plots 390

26.5 Mesh and Surface Plots of Irregular Data 396

26.6 Changing Viewpoints 398

26.7 Camera Control 400

26.8 Contour Plots 401

26.9 Specialized 3-D Plots 405

26.10 Volume Visualization 409

26.11 Easy Plotting 415

26.12 Summary 416

25.1 The p l o t Function 349

25.2 Linestyles, Markers, and Colors 350

25.3 Plot Grids, Axes Box, and Labels 353

25.4 Customizing Plot Axes 355

25.5 Multiple Plots 358

25.6 Multiple Figures 359

25.7 Subplots 360

25.8 Interactive Plotting Tools 361

25.9 Screen Updates 363

25.10 Specialized 2-D Plots 363

25.11 Easy Plotting 372

25.12 Text Formatting 374

25.13 Summary 377

xn

27 USING COLOR AND LIGHT27.1 Understanding Colormaps 422

27.2 Using Colormaps 423

27.3 Displaying Colormaps 424

27.4 Creating and Altering Colormaps 426

27 .5 Using Color to Describe a Fourth Dimension 428

27.6 Lighting Models 431

27.7 Summary 434

Contents

421

29 PRINTING AND EXPORTING GRAPHICS 44929.1 Printing and Exporting Using Menus 450

29.2 Command Line Printing and Exporting 452

29.3 Printers and Export File Formats 453

29.4 PostScript Support 456

29.5 Choosing a Renderer 457

29.6 Handle Graphics Properties 458

29.7 Setting Defaults 461

29.8 Summary 462

30 HANDLE GRAPHICS 46330.1 Objects 463

30.2 Object Handles 464

30.3 Object Properties 466

28 IMAGES, MOVIES, AND SOUND

437

28.1 Images 437

28.2 Image Formats 439

28.3 Image Files 440

28.4 Movies 443

28.5 Image Utilities 444

28.6 Sound 445

28.7 Summary 446

Contents X111

30.4

get and set 466

475

30.5 Finding Objects 474

30.6 Selecting Objects with the Mouse

30.7

Position and Units

30.8

Default Properties

30.9 Common Properties

476

479

481

30.10

30.11

30.12

30.13

30.14

New Plots 484

Rendering Speed 485

Callbacks 486

M-file Examples 487

Summary 491

31 GRAPHICAL USER INTERFACES 495

31 .1 What's a GUI? 495

31 .2 Who Should Create GUIs and Why? 496

31.3 GUI Object Hierarchy 497

31.4 Menus 497

31.5 Menu and Submenu Creation 498

31.6 Menu Properties 498

31.7 Menu Appearance 500

31.8 Contextual Menus 500

31.9 Controls 501

31.10 Control Properties 502

31 .11 Control Styles 504

31 .12 Control Size and Font Selection 507

31 .13 Capturing Mouse Actions 507

31 .14 The Event Queue 509

31 .15 Callback Programming 510

31 .16 M-file Examples 513

31 .17 GUIDE 517

31 .18 Summary 517

35 EXTENDING MATLAB WITH JAVA

35.10 Summary 639

603

35.1 Java Overview 603

35.2 Java Classes 605

35.3 Java Objects 606

35.4 Java Methods 608

35.5 Object Properties 610

35.6 Data Exchange 612

35.7 Java Arrays 615

35.8 Java Functions 626

35.9 Examples 627

xiv Contents

32 DIALOG BOXES 521

32.1

File Selection 521

32.2 Color Selection 524

32.3 Font Selection 525

32.4 M-file Dialog Boxes 526

32.5 Summary 528

33 MATLAB CLASSES AND OBJECTORIENTED PROGRAMMING 529

33.1

33.2

33.3

33.4

33.5

Overloading 530

Class Creation 537

Subscripts 549

Converter Functions 558

Precedence, Inheritance, and Aggregation 559

34 MATLAB PROGRAMMING INTERFACES 561

34.1 Accessing MATLAB Arrays 562

34.2 Calling C or FORTRAN from MATLAB 564

34.3 Calling MATLAB from C or FORTRAN 583

34.4 Exchanging Data with MAT Files 593

34.5 Summary 602

38.12 Summary 744

Contents xv

36 WINDOWS APPLICATION INTEGRATION 64136.1 ActiveX: Client/Server Communication 642

36.2 Dynamic Data Exchange 655

36.3 MATLAB Notebook 659

36.4 Summary 663

37 GETTING HELP 66537.1 Command Window Help 665

37 .2 The Help Browser 667

37 .3 Internet Resources 668

37 .4 Mastering MATLAB 6 Help 668

37.5 Summary 668

38 EXAMPLES, EXAMPLES, EXAMPLES 67138.1 Vectorization 671

38 .2 Up-Down Sequence 673

38 .3 Vandermonde Matrix 679

38.4 Repeated Value Creation and Counting 685

38.5 Circular Addressing 696

38.6 Indexing Array Segments 703

38.7 Vector Subdivision 709

38.8 Finding Indices 712

38.9 Differential Sums 720

38.10 Array Expansion 729

38.11 Structure Manipulation 734

APPENDICES

A: COMMON HANDLE GRAPHICS PROPERTIES 745

B: AXES OBJECT PROPERTIES 749

C: FIGURE OBJECT PROPERTIES 757

xvi Contents

D: IMAGE OBJECT PROPERTIES 765

E: LIGHTOBJECT PROPERTIES 767

F: LINE OBJECT PROPERTIES 769

G : PATCH OBJECT PROPERTIES 773

H : RECTANGLE OBJECT PROPERTIES 779

1 : ROOT OBJECT PROPERTIES 781

J: SURFACE OBJECT PROPERTIES 785

K: TEXT OBJECT PROPERTIES 791

L: UICONTEXTMENU AND UlMENU OBJECT PROPERTIES 795

M: UICONTROL OBJECT PROPERTIES 799

INDEX 803