MATLAB
Table of Contents Introduction.*.. 7 About This Book 1 Foolish Assumptions 2 Icons Used in This Book 3 Beyond the Book 3 Where to Go from Here 4 Part /: Getting Started With MATLAB 5 Chapter 1: Introducing MATLAB and Its Many Uses 7 Putting MATLAB in Its Place 8 Understanding how MATLAB relates to a Turing machine 8 Using MATLAB as more than a calculator 10 Determining why you need MATLAB 11 Discovering Who Uses MATLAB for Real-World Tasks 13 Knowing How to Get the Most from MATLAB 14 Getting the basic computer skills 15 Defining the math requirements 15 Applying what you know about other procedural languages 16 Understanding how this book will help you 16 Getting Over the Learning Curve 17 Chapter 2: Starting Your Copy of MATLAB 19 Installing MATLAB 19 Discovering which platforms MATLAB supports 19 Getting your copy of MATLAB 20 Performing the installation 21 Activating the product 21 Meeting the MATLAB Interface 22 Starting MATLAB for the first time 22 Employing the Command window 24 Using the Current Folder toolbar 27 Viewing the Current Folder window 28 Changing the MATLAB layout 33
MATLAB For Dummies Chapter 3: Interacting with MATLAB 37 Using MATLAB as a Calculator 38 Entering information at the prompt 38 Entering a formula 40 Copying and pasting formulas 41 Changing the Command window formatting 42 Suppressing Command window output 44 Understanding the MATLAB Math Syntax 44 Adding, subtracting, multiplying, and dividing 45 Working with exponents 47 Organizing Your Storage Locker 48 Using ans the default storage locker 48 Creating your own storage lockers 48 Operating MATLAB as More Than a Calculator 50 Learning the truth 50 Using the built-in functions 52 Accessing the function browser 52 Recovering from Mistakes 54 Understanding the MATLAB error messages 54 Stopping MATLAB when it hangs 55 Getting Help 55 Exploring the documentation 56 Working through the examples 56 Relying on peer support 57 Obtaining training 57 Requesting support from MathWorks 58 Contacting the authors 58 Chapter 4: Starting, Storing, and Saving MATLAB Files 59 Examining MATLAB's File Structure 60 Understanding the MATLAB files and what they do 60 Exploring folders with the GUI 61 Exploring folders with commands 65 Working with files in MATLAB 69 Accessing and Sharing MATLAB Files 72 Opening 72 Importing 73 Exporting 75 Saving Your Work 76 Saving variables with the GUI 76 Saving variables using commands 77 Saving commands with the GUI 77 Saving commands using commands 77
Table of Contents Part //; Manipulating and Plotting Data in MATLAB 79 Chapter 5: Embracing Vectors, Matrices, and Higher Dimensions... 81 Working with Vectors and Matrices 81 Understanding MATLAB's perspective of linear algebra 82 Entering data 83 Adding and Subtracting 88 Understanding the Many Ways to Multiply and Divide 89 Performing scalar multiplication and division 90 Employing matrix multiplication 90 Effecting matrix division 94 Creating powers of matrices 95 Working element by element 96 Using complex numbers 97 Working with exponents 99 Working with Higher Dimensions 99 Creating a multidimensional matrix 100 Accessing a multidimensional matrix 102 Replacing individual elements 103 Replacing a range of elements 104 Modifying the matrix size 105 Using cell arrays and structures 107 Using the Matrix Helps 110 Chapter 6: Understanding Plotting Basics 115 Considering Plots 115 Understanding what you can do with plots 116 Comparing MATLAB plots to spreadsheet graphs 116 Creating a plot using commands 117 Creating a plot using the Workspace window 119 Creating a plot using the Plots tab options 120 Using the Plot Function 122 Working with line color, markers, and line style 122 Creating multiple plots in a single command 124 Modifying Any Plot 124 Making simple changes 125 Adding to a plot 125 Deleting a plot 128 Working with subplots 128 Plotting with 2D Information 132
MATLAB For Dummies Chapter 7: Using Advanced Plotting Features 135 Plotting with 3D Information 136 Using the bar() function to obtain a flat 3D plot 136 Using bar3() to obtain a dimensional 3D plot 140 Using barh() and more 142 Enhancing Your Plots 143 Getting an axes handle 143 Modifying axes labels 144 Adding a title 145 Rotating label text 147 Employing annotations 148 Printing your plot 150 Part Ilk Streamtimnq MATLAB 151 Chapter 8: Automating Your Work 153 Understanding What Scripts Do 154 Creating less work for yourself 154 Defining when to use a script 155 Creating a Script 155 Writing your first script 156 Using commands for user input 158 Copying and pasting into a script 159 Converting the Command History into a script 160 Continuing long strings 160 Adding comments to your script 162 Revising Scripts 167 Calling Scripts 167 Improving Script Performance 168 Analyzing Scripts for Errors 169 Chapter 9: Expanding MATLAB's Power with Functions 171 Working with Built-in Functions 172 Learning about built-in functions 172 Sending data in and getting data out 177 Creating a Function 178 Understanding script and function differences 179 Understanding built-in function and custom function differences 179 Writing your first function 180 Using the new function 182 Passing data in 184 Passing data out 185
Table of Contents #1 Creating and using global variables 187 Using subfunctions 188 Nesting functions 190 Using Other Types of Functions 190 Inline functions 191 Anonymous functions 191 Chapter 10: Adding Structure to Your Scripts 193 Making Decisions 193 Using the if statement 194 Using the switch statement 199 Understanding the switch difference 200 Deciding between if and switch 201 Creating Recursive Functions 201 Performing Tasks Repetitively 205 Using the for statement 205 Using the while statement 206 Ending processing using break 207 Ending processing using return 208 Determining which loop to use 210 Creating Menus 210 Part W: Employing Advanced MAILAB Techniques 213 Chapter 11: Importing and Exporting Data 215 Importing Data 216 Performing import basics 216 Importing mixed strings and numbers 221 Defining the delimiter types 223 Importing selected rows or columns 224 Exporting Data 225 Performing export basics 225 Exporting scripts and functions 228 Working with Images 229 Exporting images 230 Importing images 231 Chapter 12: Printing and Publishing Your Work 233 Using Commands to Format Text 233 Modifying font appearance 234 Using special characters 241 Adding math symbols 243
MATLAB For Dummies Publishing Your MATLAB Data 248 Performing advanced script and function publishing tasks 248 Saving your figures to disk 252 Printing Your Work 253 Configuring the output page 253 Printing the data 255 Chapter 13: Recovering from Mistakes 257 Working with Error Messages 258 Responding to error messages 258 Understanding the MException class 260 Creating error and warning messages 262 Setting warning message modes 264 Understanding Quick Alerts 265 Relying on Common Fixes for MATLAB's Error Messages 267 Making Your Own Error Messages 268 Developing the custom error message 268 Creating useful error messages 272 Using Good Coding Practices 273 Part V: Specific MATLAB Applications 277 Chapter 14: Solving Equations and Finding Roots 279 Working with the Symbolic Math Toolbox 279 Obtaining your copy of the Toolbox 280 Installing the Symbolic Math Toolbox 282 Working with the GUI 286 Typing a simple command in the Command window 290 Performing Algebraic Tasks 291 Differentiating between numeric and symbolic algebra 291 Solving quadratic equations 293 Working with cubic and other nonlinear equations 294 Understanding interpolation 295 Working with Statistics 297 Understanding descriptive statistics 297 Understanding robust statistics 302 Employing least squares fit 302 Chapter 15: Performing Analysis 307 Using Linear Algebra 308 Working with determinants 308 Performing reduction 308 Using eigenvalues 310 Understanding factorization 311
Table of Contents «««Kill Employing Calculus 312 Working with differential calculus 312 Using integral calculus 313 Working with multivariate calculus 314 Solving Differential Equations 316 Using the numerical approach 316 Using the symbolic approach 317 Chapter 16: Creating Super Plots 319 Understanding What Defines a Super Plot 320 Using the Plot Extras 321 Using grid() 321 Obtaining the current axis using gca 322 Creating axis dates using datetick( ) 322 Creating plots with colorbar( ) 326 Interacting with daspect 329 Interacting with pbaspect 332 Working with Plot Routines 334 Finding data deviations using errorbar( ) 334 Ranking related measures using pareto( ) 334 Plotting digital data using stairs() 335 Showing data distribution using stem( ) 336 Drawing images using fill 337 Displaying velocity vectors using quiver() 340 Displaying velocity vectors using feather( ) 340 Displaying velocity vectors using compass( ) 340 Working with polar coordinates using polar() 342 Displaying angle distribution using rose( ) 342 Spotting sparcity patterns using spy( ) 344 Employing Animation 344 Working with movies 346 Working with objects 347 Performing data updates 348 Part VI: The Part of Tens 351 Chapter 17: Top Ten Uses of MATLAB 353 Engineering New Solutions 353 Getting an Education 354 Working with Linear Algebra 355 Performing Numerical Analysis 355 Getting Involved in Science 356 Engaging Mathematics 356 Exploring Research 356
MATLAB For Dummies Walking through a Simulation 357 Employing Image Processing 358 Embracing Programming Using Computer Science 358 Chapter 18: Ten Ways to Make a Living Using MATLAB 361 Working with Green Technology 362 Looking for Unexploded Ordinance 362 Creating Speech Recognition Software 363 Getting Disease under Control 363 Becoming a Computer Chip Designer 364 Keeping the Trucks Rolling 364 Creating the Next Generation of Products 364 Designing Equipment Used in the Field 365 Performing Family Planning 365 Reducing Risks Using Simulation 366 Appendix A: MATLAB Functions 367 Appendix B: MATLAB's Plotting Routines 377 index - 385