Author(s): The MathWorks
Publisher: The MathWorks
Year: 2005
Language: English
Pages: 680
Data Structures......Page 23
Creating and Concatenating Matrices......Page 25
Specialized Matrix Functions......Page 26
Concatenating Matrices......Page 29
Matrix Concatenation Functions......Page 30
Generating a Numeric Sequence......Page 32
Combining Unlike Data Types......Page 33
Accessing Single Elements......Page 39
Linear Indexing......Page 40
Accessing Multiple Elements......Page 41
Logical Indexing......Page 43
Indexing on Assignment......Page 44
Dimensions of the Matrix......Page 45
Data Types Used in the Matrix......Page 46
Data Structures Used in the Matrix......Page 47
Expanding the Size of a Matrix......Page 48
Diminishing the Size of a Matrix......Page 52
Reshaping a Matrix......Page 53
Preallocating Memory......Page 55
Shifting the Location of Matrix Elements......Page 57
Sorting the Data in Each Row......Page 59
Sorting Row Vectors......Page 60
Constructing a Matrix from a Diagonal Vector......Page 61
Concatenating Matrices Diagonally......Page 62
The Empty Matrix......Page 63
Vectors......Page 66
Sparse Matrix Functions......Page 68
Overview......Page 70
Creating Multidimensional Arrays......Page 72
Indexing Multidimensional Arrays......Page 76
Reshaping Multidimensional Arrays......Page 80
Permuting Array Dimensions......Page 82
Computing with Multidimensional Arrays......Page 84
Organizing Data in Multidimensional Arrays......Page 86
Multidimensional Cell Arrays......Page 88
Multidimensional Structure Arrays......Page 89
Summary of Matrix and Array Functions......Page 91
Data Types......Page 95
Overview of MATLAB Data Types......Page 96
Integers......Page 98
Floating-Point Numbers......Page 100
Complex Numbers......Page 105
Infinity and NaN......Page 106
Display Format for Numeric Values......Page 108
Function Summary......Page 110
Creating a Logical Array......Page 114
How Logical Arrays Are Used......Page 116
Identifying Logical Arrays......Page 118
Creating Character Arrays......Page 119
Cell Arrays of Strings......Page 121
String Comparisons......Page 124
Searching and Replacing......Page 127
Converting from Numeric to String......Page 128
Converting from String to Numeric......Page 130
Function Summary......Page 132
Types of Date Formats......Page 135
Conversions Between Date Formats......Page 137
Output Formats......Page 138
Current Date and Time......Page 140
Function Summary......Page 141
Structures......Page 143
Building Structure Arrays......Page 144
Accessing Data in Structure Arrays......Page 147
Using Dynamic Field Names......Page 148
Finding the Size of Structure Arrays......Page 149
Applying Functions and Operators......Page 150
Writing Functions to Operate on Structures......Page 151
Organizing Data in Structure Arrays......Page 153
Nesting Structures......Page 157
Function Summary......Page 159
Cell Arrays......Page 160
Creating Cell Arrays......Page 161
Obtaining Data from Cell Arrays......Page 164
Replacing Lists of Variables with Cell Arrays......Page 166
Applying Functions and Operators......Page 168
Organizing Data in Cell Arrays......Page 169
Nesting Cell Arrays......Page 170
Cell Arrays of Structures......Page 172
Function Summary......Page 173
Calling a Function Using Its Handle......Page 174
Simple Function Handle Example......Page 175
MATLAB Classes......Page 176
Java Classes......Page 177
Basic Program Components......Page 179
Types of Variables......Page 180
Naming Variables......Page 184
Scope of a Variable......Page 185
Lifetime of a Variable......Page 186
Keywords......Page 187
Special Values......Page 188
Arithmetic Operators......Page 190
Relational Operators......Page 191
Logical Operators......Page 193
Operator Precedence......Page 198
String Evaluation......Page 200
Shell Escape Functions......Page 201
MATLAB Regular Expression Functions......Page 203
Character Classes......Page 204
Character Representation......Page 207
Logical Operators......Page 208
Lookaround Operators......Page 211
Quantifiers......Page 214
Tokens......Page 218
Handling Multiple Strings......Page 224
Operator Summary......Page 228
Generating a List from a Cell Array......Page 232
Generating a List from a Structure......Page 233
How to Use the Comma-Separated List......Page 234
Fast Fourier Transform Example......Page 236
Conditional Control — if, switch......Page 238
Loop Control — for, while, continue, break......Page 242
Error Control — try, catch......Page 245
Program Termination — return......Page 246
Symbol Reference......Page 247
At — @......Page 248
Colon — :......Page 249
Comma — ,......Page 250
Dot — .......Page 251
Dot-Dot-Dot (Ellipsis) — .........Page 252
Exclamation Point — !......Page 253
Percent — %......Page 254
Semicolon — ;......Page 255
Space Character......Page 256
Square Brackets — [ ]......Page 257
M-File Functions......Page 259
Built-In Functions......Page 260
Overloaded MATLAB Functions......Page 261
M-File Programming......Page 263
Creating a Program......Page 264
Getting the Bugs Out......Page 265
Cleaning Up the Program......Page 266
Improving Performance......Page 267
Checking It In......Page 268
Types of M-Files......Page 269
Basic Parts of an M-File......Page 270
Creating a Simple M-File......Page 275
Creating P-Code Files......Page 277
M-File Scripts......Page 278
M-File Functions......Page 279
Types of Functions......Page 280
Identifying Dependencies......Page 281
Checking the Number of Input Arguments......Page 283
Passing Variable Numbers of Arguments......Page 285
Returning Output Arguments......Page 287
Constructing a Function Handle......Page 289
Calling a Function Using Its Handle......Page 290
Additional Information on Function Handles......Page 291
Determining Which Function Is Called......Page 293
MATLAB Calling Syntax......Page 296
Passing Certain Argument Types......Page 299
Passing Arguments in Structures or Cell Arrays......Page 301
Calling External Functions......Page 302
Types of Functions......Page 303
Overview of MATLAB Function Types......Page 304
Constructing an Anonymous Function......Page 305
Arrays of Anonymous Functions......Page 307
Outputs from Anonymous Functions......Page 308
Variables Used in the Expression......Page 310
Examples of Anonymous Functions......Page 313
Primary M-File Functions......Page 316
Writing Nested Functions......Page 317
Calling Nested Functions......Page 319
Variable Scope in Nested Functions......Page 320
Using Function Handles with Nested Functions......Page 322
Examples of Nested Functions......Page 327
Subfunctions......Page 333
Accessing Help for a Subfunction......Page 334
Accessing Help for a Private Function......Page 335
Class Directories......Page 336
Data Import and Export......Page 337
Text Data......Page 339
Scientific Formats......Page 340
Large Data Sets......Page 341
Toolboxes for Importing Data......Page 342
Using the Import Wizard with Text Data......Page 343
Using the Import Wizard with Binary Data......Page 349
Supported File Formats......Page 352
Exporting Data to MAT-Files......Page 354
Importing Data from MAT-Files......Page 360
Using Import Functions with Text Data......Page 364
Importing Numeric Text Data......Page 367
Importing Numeric Data with Text Headers......Page 368
Importing Mixed Alphabetic and Numeric Data......Page 369
Importing from XML Documents......Page 371
Exporting Text Data......Page 372
Exporting Delimited ASCII Data Files......Page 373
Using the diary Function to Export Data......Page 375
Exporting to XML Documents......Page 376
Getting Information About Graphics Files......Page 377
Exporting Graphics Data......Page 378
Getting Information About Audio/Video Files......Page 380
Importing Audio/Video Data......Page 381
Exporting Audio/Video Data......Page 382
Microsoft Excel Spreadsheets......Page 384
Lotus 123 Spreadsheets......Page 387
Working with Common Data Format (CDF) Files......Page 390
Working with Flexible Image Transport System (FITS) Files......Page 393
Working with Hierarchical Data Format (HDF5) Files......Page 395
Using the HDF Import Tool......Page 405
Using the HDF4 Import Tool Subsetting Options......Page 410
Using the MATLAB hdfread Function......Page 420
Using the HDF4 Command-Line Interface......Page 424
Example: Exporting Data to an HDF4 File......Page 432
Using the MATLAB HDF Utility API......Page 439
Using Low-Level File I/O Functions......Page 441
Opening Files......Page 442
Reading Binary Data......Page 444
Controlling Position in a File......Page 446
Reading Strings Line by Line from Text Files......Page 448
Reading Formatted ASCII Data......Page 450
Writing Formatted Text Files......Page 451
Closing a File......Page 453
Downloading Web Content and Files......Page 454
Creating and Uncompressing Zip Archives......Page 456
Sending E-Mail......Page 457
Performing FTP File Operations......Page 459
Error Handling......Page 463
Checking for Errors with try-catch......Page 464
Nested try-catch Blocks......Page 465
Reporting an Error......Page 466
Identifying the Cause......Page 467
Regenerating an Error......Page 469
Identifier Format......Page 470
Using Message Identifiers with lasterr......Page 471
Reporting a Warning......Page 474
Identifying the Cause......Page 475
Warning Statements......Page 476
Warning Control Statements......Page 477
Output from Control Statements......Page 479
Saving and Restoring State......Page 482
Debug, Backtrace, and Verbose Modes......Page 483
Debugging Errors and Warnings......Page 485
Classes and Objects......Page 487
Features of Object-Oriented Programming......Page 488
MATLAB Data Class Hierarchy......Page 489
Invoking Methods on Objects......Page 490
Debugging Class Methods......Page 491
Setting Up Class Directories......Page 492
Tips for C++ and Java Programmers......Page 493
The MATLAB Canonical Class......Page 495
The Class Constructor Method......Page 496
Identifying Objects Outside the Class Directory......Page 497
The display Method......Page 498
The set and get Methods......Page 499
Indexed Reference Using subsref and subsasgn......Page 500
Handling Subscripted Reference......Page 501
Handling Subscripted Assignment......Page 503
Object Indexing Within Methods......Page 504
Indexing an Object with Another Object......Page 505
Converter Methods......Page 506
Overloading Operators......Page 507
Overloading Functions......Page 509
The Polynom Constructor Method......Page 510
Converter Methods for the Polynom Class......Page 511
The Polynom display Method......Page 514
Overloading Arithmetic Operators for polynom......Page 515
Overloading Functions for the Polynom Class......Page 517
Listing Class Methods......Page 519
Simple Inheritance......Page 521
Aggregation......Page 523
Inheritance Model for the Asset Class......Page 524
The Asset Constructor Method......Page 525
The Asset set Method......Page 527
The Asset subsref Method......Page 528
The Asset subsasgn Method......Page 529
The Asset display Method......Page 530
Designing the Stock Class......Page 531
The Stock Constructor Method......Page 532
The Stock get Method......Page 534
The Stock set Method......Page 535
The Stock subsref Method......Page 536
The Stock subsasgn Method......Page 537
The Stock display Method......Page 539
Designing the Portfolio Class......Page 540
The Portfolio Constructor Method......Page 541
The Portfolio display Method......Page 542
The Portfolio pie3 Method......Page 543
Creating a Portfolio......Page 544
Modifying Objects During Save or Load......Page 546
Summary of Code Changes......Page 547
The loadobj Method......Page 548
Changing the Portfolio Constructor......Page 549
The Portfolio subsref Method......Page 550
Object Precedence......Page 551
Specifying Precedence of User-Defined Classes......Page 552
Selecting a Method......Page 553
Querying Which Method MATLAB Will Call......Page 556
Scheduling Program Execution with Timers......Page 557
Using a MATLAB Timer Object......Page 558
Example: Displaying a Message......Page 559
Creating Timer Objects......Page 560
Timer Object Naming......Page 561
Retrieving the Value of Timer Object Properties......Page 562
Setting the Value of Timer Object Properties......Page 563
Starting a Timer......Page 565
Stopping Timer Objects......Page 566
Blocking the MATLAB Command Line......Page 567
Associating Commands with Timer Object Events......Page 569
Creating Callback Functions......Page 570
Specifying the Value of Callback Function Properties......Page 572
Executing a Timer Callback Function Once......Page 574
Executing a Timer Callback Function Multiple Times......Page 575
Handling Callback Function Queuing Conflicts......Page 576
Deleting All Existing Timer Objects......Page 578
Finding Invisible Timer Objects......Page 579
Improving Performance and Memory Usage......Page 581
Stopwatch Timer Functions......Page 582
Vectorizing Loops......Page 584
Preallocating Arrays......Page 587
Assigning to Variables......Page 589
Using Appropriate Logical Operators......Page 590
Avoid Large Background Processes......Page 591
Memory Management Functions......Page 592
Working with Variables......Page 593
Working with Large Amounts of Data......Page 595
Compressing Data in Memory......Page 596
Increasing System Swap Space......Page 597
Reloading Variables on UNIX Systems......Page 598
Programming Tips......Page 599
Command Line Continuation......Page 601
Recalling Commands......Page 602
Suppressing Output to the Screen......Page 603
Using the Help Browser......Page 604
Topical Help......Page 605
Writing Your Own Help......Page 606
Help for Methods and Overloaded Functions......Page 607
Using the Find and Replace Utility......Page 608
Editing M-Files in EMACS......Page 609
Using Lowercase for Function Names......Page 610
Dependent Functions, Built-Ins, Classes......Page 611
Variable Numbers of Arguments......Page 612
Passing Arguments in a Cell Array......Page 613
Selecting the Right Data Structures......Page 614
The Importance of Comments......Page 615
Testing the Final Program......Page 616
More Debug Functions......Page 617
A Quick Way to Examine Variables......Page 618
Locating an Error from the Error Message......Page 619
Debugging Scripts......Page 620
Making Sure Variable Names Are Valid......Page 621
Avoid Using i and j for Variables......Page 622
Protecting Persistent Variables......Page 623
Global Variables......Page 624
Comparing Methods of Concatenation......Page 625
Converting Between Strings and Cell Arrays......Page 626
Search and Replace Using Regular Expressions......Page 627
Assigning to a Series of Variables......Page 628
Changing the Counter Variable within a for Loop......Page 629
Precedence Rules......Page 630
Handles to Functions Not on the Path......Page 631
Making Toolbox File Changes Visible to MATLAB......Page 632
Change Notification on Windows......Page 633
Using break, continue, and return......Page 634
Multiple Conditions in a case Statement......Page 635
Catching Errors with try-catch......Page 636
Forcing an Early Return from a Function......Page 637
Loading Data into the Workspace......Page 638
Appending to a MAT-File......Page 639
Saving to an ASCII File......Page 640
Naming Other Files......Page 641
Determining Filenames at Run-Time......Page 642
Returning the Size of a File......Page 643
Readable File Formats......Page 644
Reading Files with Different Formats......Page 645
Interactive Input into Your Program......Page 646
Getting MATLAB to Start Up Faster......Page 647
Constructing Paths and Filenames......Page 648
Temporary Directories and Filenames......Page 649
Demos Available with MATLAB......Page 650
For More Information......Page 651
External Interfaces......Page 653
Finding the Documentation in Online Help......Page 654
Reference Documentation......Page 657
Index......Page 659