ebook img

MATLAB Recipes: A Problem-Solution Approach PDF

314 Pages·2015·12.533 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview MATLAB Recipes: A Problem-Solution Approach

MATLAB Recipes A Problem-Solution Approach Michael Paluszek Stephanie Thomas MATLAB Recipes: A Problem-Solution Approach Michael Paluszek Stephanie Thomas Princeton, New Jersey, USA Princeton Junction, New Jersey, USA ISBN-13 (pbk): 978-1-4842-0560-0 ISBN-13 (electronic): 978-1-4842-0559-4 DOI 10.1007/978-1-4842-0559-4 Library of Congress Control Number: 2015955885 Copyright © 2015 by Michael Paluszek and Stephanie Thomas This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher’s location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director: Welmoed Spahr Lead Editor: Steve Anglin Technical Reviewer: Jonah Lissner Editorial Board: Steve Anglin, Louise Corrigan, Jonathan Gennick, Robert Hutchinson, Michelle Lowman, James Markham, Susan McDermott, Matthew Moodie, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Gwenan Spearing, Steve Weiss Coordinating Editor: Mark Powers Copy Editor: Kim Burton-Weisman Compositor: SPi Global Indexer: SPi Global Artist: SPi Global Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail [email protected], or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales– eBook Licensing web page at www.apress.com/bulk-sales. Any source code or other supplementary materials referenced by the author in this text is available to readers at www.apress.com/9781484205600. For detailed information about how to locate your book’s source code, go to www.apress.com/source-code/. Readers can also access source code at SpringerLink in the Supplementary Material section for each chapter. Printed on acid-free paper For Marilyn and Matt Contents at a Glance About the Authors ...................................................................................................xix About the Technical Reviewer ................................................................................xxi Introduction ..........................................................................................................xxiii ■ Part I: Coding in MATLAB ....................................................................1 ■ Chapter 1: Coding Handbook .................................................................................3 ■ Chapter 2: MATLAB Style .....................................................................................31 ■ Chapter 3: Visualization ......................................................................................57 ■ Chapter 4: Interactive Graphics ...........................................................................93 ■ Chapter 5: Testing and Debugging .....................................................................117 ■ Part II: Applications ........................................................................137 ■ Chapter 6: The Double Integrator ......................................................................139 ■ Chapter 7: Robotics ...........................................................................................159 ■ Chapter 8: Electric Motors .................................................................................177 ■ Chapter 9: Fault Detection .................................................................................205 ■ Chapter 10: Chemical Processes .......................................................................227 ■ Chapter 11: Aircraft ...........................................................................................249 ■ Chapter 12: Spacecraft ......................................................................................273 Index .....................................................................................................................295 v Contents About the Authors ...................................................................................................xix About the Technical Reviewer ................................................................................xxi Introduction ..........................................................................................................xxiii ■ Part I: Coding in MATLAB ....................................................................1 ■ Chapter 1: Coding Handbook .................................................................................3 MATLAB Language Primer ................................................................................................3 A Brief Introduction to MATLAB ..............................................................................................................3 Everything Is a Matrix .............................................................................................................................7 Strings Are Simple ..................................................................................................................................8 Use Strict Data Structures ......................................................................................................................8 Cell Arrays Hold Anything and Everything .............................................................................................10 Optimize Your Code with Logical Arrays ...............................................................................................11 Use Persistent and Global Scope to Minimize Data Passing ................................................................11 Understanding Unique MATLAB Operators and Keywords ....................................................................13 Harnessing the Power of Multiple Inputs and Outputs .........................................................................15 Use Function Handles for Effi ciency .....................................................................................................15 Advanced Data Types ............................................................................................................................16 Primer Recipes ...............................................................................................................17 1-1. Creating Function Help ...........................................................................................17 Problem ................................................................................................................................................17 Solution.................................................................................................................................................17 How It Works .........................................................................................................................................17 vii ■ CONTENTS 1-2. Locating Directories for Data Storage .....................................................................19 Problem ................................................................................................................................................19 Solution.................................................................................................................................................19 How It Works .........................................................................................................................................19 1-3. Loading Binary Data from a File .............................................................................20 Problem ................................................................................................................................................20 Solution.................................................................................................................................................20 How It Works .........................................................................................................................................20 1-4. Command-Line File Interaction ...............................................................................22 Problem ................................................................................................................................................22 Solution.................................................................................................................................................22 How It Works .........................................................................................................................................22 1-5. Using a MEX File to Link to an External Library ......................................................23 Problem ................................................................................................................................................23 Solution.................................................................................................................................................23 How It Works .........................................................................................................................................24 1-6. Protect Your IP with Parsed Files ............................................................................26 Problem ................................................................................................................................................26 Solution.................................................................................................................................................26 How It Works .........................................................................................................................................26 1-7. Writing to a Text File ...............................................................................................27 Problem ................................................................................................................................................27 Solution.................................................................................................................................................27 How It Works .........................................................................................................................................27 Summary ........................................................................................................................30 ■ Chapter 2: MATLAB Style .....................................................................................31 2-1. Developing Your Own MATLAB Style Guidelines .....................................................31 Problem ................................................................................................................................................31 Solution.................................................................................................................................................31 How It Works .........................................................................................................................................31 viii ■ CONTENTS 2-2. Writing Good Function Help ....................................................................................35 Problem ................................................................................................................................................35 Solution.................................................................................................................................................35 How It Works .........................................................................................................................................35 2-3. Overloading Functions and Utilizing varargin .........................................................37 Problem ................................................................................................................................................37 Solution.................................................................................................................................................37 How It Works .........................................................................................................................................38 2-4. Adding Built-in Inputs and Outputs to Functions ....................................................39 Problem ................................................................................................................................................39 Solution.................................................................................................................................................39 How It Works .........................................................................................................................................39 2-5. Smart Structuring of Scripts ...................................................................................40 Problem ................................................................................................................................................40 Solution.................................................................................................................................................40 How It Works .........................................................................................................................................41 2-6. Implementing MATLAB Command-Line Help for Folders ........................................42 Problem ................................................................................................................................................42 Solution.................................................................................................................................................43 How It Works .........................................................................................................................................43 2-7. Publishing Code into Technical Reports ..................................................................45 Problem ................................................................................................................................................45 Solution.................................................................................................................................................45 How It Works .........................................................................................................................................45 2-8. Integrating Toolbox Documentation into the MATLAB Help System ........................49 Problem ................................................................................................................................................49 Solution.................................................................................................................................................49 How It Works .........................................................................................................................................50 ix

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.