Introduction 1
About This Book 1
Foolish Assumptions 2
Icons Used in This Book 3
Beyond the Book 4
Where to Go from Here 4
Part 1: Getting Started With MATLAB 7
Chapter 1: Introducing MATLAB and Its Many Uses 9
Putting MATLAB in Its Place 10
Understanding how MATLAB relates to a Turing machine 10
Using MATLAB as more than a calculator 13
Determining why you need MATLAB 14
Discovering Who Uses MATLAB for Real-World Tasks 17
Knowing How to Get the Most from MATLAB 18
Getting the basic computer skills 18
Defining the math requirements 19
Applying what you know about other procedural languages 19
Understanding how this book will help you 20
Getting Over the Learning Curve 20
Chapter 2: Starting Your Copy of MATLAB 21
Installing MATLAB 22
Discovering which platforms MATLAB supports 22
Getting your copy of MATLAB 23
Performing the installation 23
Activating the product 24
Meeting the MATLAB Interface 25
Starting MATLAB for the first time 25
Considering the default Toolstrip tabs 27
Working with the Quick Access toolbar (QAT) 29
Employing the Command Window 30
Getting additional help with MATLAB 31
Using the Current Folder toolbar 32
Viewing the Current Folder window 32
Changing the MATLAB layout 38
Chapter 3: Interacting with MATLAB 41
Using MATLAB as a Calculator 42
Entering information at the prompt 42
Entering a formula 44
Copying and pasting formulas 44
Changing the Command Window formatting 46
Suppressing Command Window output 47
Understanding the MATLAB Math Syntax 48
Adding, subtracting, multiplying, and dividing 48
Working with exponents 50
Organizing Your Storage Locker 51
Using ans - the default storage locker 52
Creating your own storage lockers 52
Operating MATLAB as More Than a Calculator 54
Learning the truth 54
Using the built-in functions 54
Accessing the function browser 56
Recovering from Mistakes 57
Understanding the MATLAB error messages 58
Stopping MATLAB when it hangs 58
Chapter 4: Starting, Storing, and Saving MATLAB Files 61
Examining MATLAB's File Structure 62
Understanding the MATLAB files and what they do 63
Exploring folders with the GUI 65
Exploring folders with commands 69
Working with files in MATLAB 72
Accessing and Sharing MATLAB Files 74
Opening 74
Exporting 75
Importing 76
Saving Your Work 78
Saving variables with the GUI 78
Saving variables using commands 78
Saving commands with the GUI 79
Saving commands using commands 79
Using online storage 80
Part 2: Manipulating and Plotting Data in MATLAB 81
Chapter 5: Embracing Vectors, Matrices, and Higher Dimensions 83
Working with Vectors and Matrices 84
Understanding MATLAB's perspective of linear algebra 84
Entering data 86
Adding and Subtracting 92
Understanding the Many Ways to Multiply and Divide 94
Performing scalar multiplication and division 94
Employing matrix multiplication 95
Dividing two vectors 98
Effecting matrix division 98
Creating powers of matrices 101
Using complex numbers 102
Working with exponents 104
Working with Higher Dimensions 105
Creating a multidimensional matrix 105
Accessing a multidimensional matrix 108
Replacing individual elements 109
Replacing a range of elements 110
Modifying the matrix size 112
Using cell arrays and structures 113
Using the Matrix Helps 117
Chapter 6: Understanding Plotting Basics 121
Considering Plots 121
Understanding what you can do with plots 122
Comparing MATLAB plots to spreadsheet graphs 122
Creating a plot using commands 123
Creating a plot using the Workspace window 125
Creating a plot using the Plots tab options 126
Using the Plot Function 128
Working with line color, markers, and line style 128
Creating multiple plots in a single command 129
Modifying Any Plot 130
Making simple changes 130
Adding to a plot 132
Deleting a plot 134
Working with subplots 134
Plotting with 2D Information 137
Chapter 7: Using Advanced Plotting Features 139
Plotting with 3D Information 140
Using the bar() function to obtain a flat 3D plot 140
Using bar3() to obtain a dimensional 3D plot 144
Using barh() and more 146
Enhancing Your Plots 147
Getting an axes handle 147
Modifying axes labels 148
Adding a title 150
Rotating label text 151
Employing annotations 153
Printing your plot 154
Using the Plot Extras 155
Creating axes dates using datetick() 155
Creating plots with colorbar() 157
Interacting with daspect 159
Interacting with pbaspect 161
Part 3: Streamlining MATLAB 163
Chapter 8: Automating Your Work 165
Understanding What Scripts Do 166
Creating less work for yourself 166
Defining when to use a script 167
Creating a Script 168
Writing your first script 168
Using commands for user input 170
Copying and pasting into a script 171
Converting the Command History into a script 172
Continuing long strings 172
Adding comments to your script 174
Revising Scripts 179
Calling Scripts 179
Improving Script Performance 180
Analyzing Scripts for Errors 181
Using the MATLAB Profiler to Improve Performance 182
Chapter 9: Expanding MATLAB's Power with Functions 185
Working with Built-in Functions 186
Learning about built-in functions 186
Sending data in and getting data out 191
Creating a Function 191
Understanding script and function differences 192
Understanding built-in function and custom function differences 193
Writing your first function 193
Using the new function 195
Passing data in 196
Passing data out 198
Creating and using global variables 199
Using subfunctions 202
Nesting functions 203
Using Other Types of Functions 204
Inline functions 204
Anonymous functions 205
Chapter 10: Adding Structure to Your Scripts 207
Making Decisions 208
Using the if statement 208
Using the switch statement 212
Understanding the switch difference 214
Deciding between if and switch 214
Creating Recursive Functions 215
Performing Tasks Repetitively 219
Using the for statement 219
Using the while statement 220
Starting a new loop iteration using continue 221
Ending processing using break 222
Ending processing using return 223
Determining which loop to use 225
Creating Menus 225
Chapter 11: Working with Live Scripts 229
Comparing a Live Script to a Regular Script 230
Working with the Live Editor 231
Opening the Live Editor 232
Working with the Output pane 232
Adding formatted text 235
Using plots within the coded area 236
Incorporating graphics 237
Incorporating controls 238
Running Live Script Sections 241
Diagnosing Coding Errors 242
Chapter 12: Working with Live Functions 245
Comparing a Live Function to a Regular Function 246
Understanding Live Function Flexibility Differences 247
Creating a Live Function 247
Running a Live Function 248
Refactoring a Live Function 249
Using the specialized coding buttons 253
Going to a specific function 254
Converting a Function to a Live Function 255
Sharing Live Functions and Live Scripts 256
Using an interactive document 256
Employing a full screen presentation 257
Working with plain text 257
Creating a static document 257
Performing Comparisons and Merges 259
Comparing Live Functions and Live Scripts 259
Merging Live Functions and Live Scripts 260
Chapter 13: Designing and Using Classes 263
A Brief Overview of Object-Oriented Programming (OOP) 264
Defining an object 264
Considering how properties define an object 265
Using methods to interact with an object 266
Listening to an object using events 267
Understanding the need for privacy 268
Understanding OOP in MATLAB 268
Comparing MATLAB OOP to other languages 269
Uses of classes and objects in MATLAB 270
Performing tasks with objects in MATLAB 271
Creating a Basic MATLAB Class 272
Starting the class 272
Adding properties 275
Specifying methods 278
Chapter 14: Creating MATLAB Apps 281
Working with the App Designer 282
Understanding apps 282
Getting apps 283
Starting the App Designer 286
Defining an Interface 290
Understanding the various components 290
Changing the component properties 292
Making the Interface Functional 293
Working with Code View 294
Creating a callback function 295
Running the App 297
Packaging Your App 298
Chapter 15: Building Projects 301
Considering the Need for Projects 302
Creating a New Project 303
Choosing a project type 303
Using the Project editor 305
Understanding the Project Dependencies 309
Running Required Checks 311
Checking project integrity 311
Looking for potential updates 311
Part 4: Employing Advanced MATLAB Techniques 315
Chapter 16: Importing and Exporting Data 317
Importing Data 318
Avoiding older import/export function calls 319
Performing import basics 319
Importing mixed strings and numbers 325
Importing selected rows or columns 327
Exporting Data 328
Performing export basics 328
Exporting scripts and functions 331
Working with Images 332
Exporting images 332
Importing images 333
Chapter 17: Printing and Publishing Your Work 335
Using Commands to Format Text 336
Modifying font appearance 336
Using special characters 344
Adding math symbols 346
Publishing Your MATLAB Data 350
Performing advanced script and function publishing tasks 350
Saving your figures to disk 354
Printing Your Work 355
Configuring the output page 355
Printing the data 356
Chapter 18: Recovering from Mistakes 357
Working with Error Messages 358
Responding to error messages 359
Understanding the MException class 361
Creating error and warning messages 362
Setting warning message modes 365
Understanding Quick Alerts 366
Relying on Common Fixes for MATLAB's Error Messages 368
Making Your Own Error Messages 369
Developing the custom error message 370
Creating useful error messages 374
Using Good Coding Practices 375
Part 5: Specific MATLAB Applications 379
Chapter 19: Solving Equations and Finding Roots 381
Working with the Symbolic Math Toolbox 382
Obtaining your copy of the Symbolic Math Toolbox 382
Installing the Symbolic Math Toolbox 384
Working with the GUI 386
Typing a simple command in the Command Window 387
Performing Algebraic Tasks 388
Differentiating between numeric and symbolic algebra 389
Solving quadratic equations 390
Working with cubic and other nonlinear equations 392
Understanding interpolation 393
Working with Statistics 395
Understanding descriptive statistics 395
Understanding robust statistics 398
Employing the Symbolic Math Toolbox for plotting 401
Chapter 20: Performing Analysis 405
Using Linear Algebra 406
Working with determinants 406
Performing reduction 407
Using eigenvalues 409
Understanding factorization 409
Employing Calculus 411
Working with differential calculus 411
Using integral calculus 413
Working with multivariate calculus 413
Solving Differential Equations 415
Using the numerical approach 415
Using the symbolic approach 416
Part 6: The Part of Tens 419
Chapter 21: The Top Ten Uses of MATLAB 421
Working with Linear Algebra 422
Performing Numerical Analysis 422
Designing a Neural Network Simulation 423
Getting Involved in Science 423
Logging Sensor Data 424
Exploring Research 424
Creating Light Animations Using Arduino 425
Employing Image Processing 425
Controlling Industrial Equipment 426
Performing Audio Compression Using Wavelets 427
Chapter 22: Ten Ways to Make a Living Using MATLAB 429
Working with Green Technology 430
Creating Speech Recognition Software 430
Performing Antenna Analysis and Design 431
Getting Disease under Control 432
Becoming a Computer Chip Designer 432
Working with Robots 433
Keeping the Trucks Rolling 433
Designing Equipment Used in the Field 434
Reducing Risks Using Simulation 434
Creating Security Solutions 435
Appendix A: MATLAB Functions 437
Appendix B: MATLAB's Plotting Routines 447
Index 453