MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

  • Syntax Basics

    • Continue Long Statements on Multiple Lines.......... 1-

    • Call Functions................................... 1-

    • Ignore Function Outputs 1-

    • Variable Names.................................. 1-

      • Valid Names.................................. 1-

      • Conflicts with Function Names.................... 1-



    • Case and Space Sensitivity......................... 1-

    • Command vs. Function Syntax 1-

      • Command and Function Syntaxes 1-

      • Avoid Common Syntax Mistakes.................. 1-

      • How MATLAB Recognizes Command Syntax......... 1-



    • Common Errors When Calling Functions 1-

      • Conflicting Function and Variable Names........... 1-

      • Undefined Functions or Variables................. 1-





  • Program Components

    • MATLAB Operators and Special Characters 2-

      • Arithmetic Operators 2-

      • Relational Operators 2-

      • Logical Operators 2-

      • Special Characters............................. 2-

      • String and Character Formatting................. 2-



    • Array vs. Matrix Operations 2-

      • Introduction................................. 2-

      • Array Operations............................. 2-

      • Matrix Operations............................ 2-



    • Compatible Array Sizes for Basic Operations 2-

      • Inputs with Compatible Sizes.................... 2-

      • Inputs with Incompatible Sizes 2-

      • Examples................................... 2-



    • Array Comparison with Relational Operators......... 2-

      • Array Comparison 2-

      • Logic Statements............................. 2-



    • Operator Precedence............................. 2-

      • Precedence of AND and OR Operators............. 2-

      • Overriding Default Precedence................... 2-



    • Average Similar Data Points Using a Tolerance....... 2-

    • Group Scattered Data Using a Tolerance............. 2-

    • Conditional Statements 2-

    • Loop Control Statements 2-

    • Regular Expressions 2-

      • What Is a Regular Expression? 2-

      • Steps for Building Expressions 2-

      • Operators and Characters 2-





  • Lookahead Assertions in Regular Expressions 2-

    • Lookahead Assertions 2-

    • Overlapping Matches.......................... 2-

    • Logical AND Conditions........................ 2-



  • Tokens in Regular Expressions..................... 2-

    • Introduction................................. 2-

    • Multiple Tokens.............................. 2-

    • Unmatched Tokens 2-

    • Tokens in Replacement Text..................... 2-

    • Named Capture.............................. 2-



  • Dynamic Regular Expressions 2-

    • Introduction................................. 2-

    • Dynamic Match Expressions — (??expr) 2-

      • 2- Commands That Modify the Match Expression — (??@cmd)

      • 2- Commands That Serve a Functional Purpose — (?@cmd)



    • Commands in Replacement Expressions — ${cmd}... 2-



  • Comma-Separated Lists.......................... 2-

    • What Is a Comma-Separated List?................ 2-

    • Generating a Comma-Separated List............... 2-

    • Assigning Output from a Comma-Separated List...... 2-

    • Assigning to a Comma-Separated List 2-

    • How to Use the Comma-Separated Lists............ 2-

    • Fast Fourier Transform Example.................. 2-



  • Alternatives to the eval Function 2-

    • Why Avoid the eval Function?.................... 2-

    • Variables with Sequential Names 2-

    • Files with Sequential Names..................... 2-

    • Function Names in Variables.................... 2-

    • Field Names in Variables....................... 2-

    • Error Handling............................... 2-



  • Overview of MATLAB Classes

    • Fundamental MATLAB Classes 3-



  • Numeric Classes

    • Integers 4-

      • Integer Classes................................ 4-

      • Creating Integer Data........................... 4-

      • Arithmetic Operations on Integer Classes............ 4-

      • Largest and Smallest Values for Integer Classes....... 4-



    • Floating-Point Numbers........................... 4-

      • Double-Precision Floating Point................... 4-

      • Single-Precision Floating Point.................... 4-

      • Creating Floating-Point Data...................... 4-

      • Arithmetic Operations on Floating-Point Numbers..... 4-

        • 4- Largest and Smallest Values for Floating-Point Classes



      • Accuracy of Floating-Point Data 4-

        • 4- Avoiding Common Problems with Floating-Point Arithmetic





    • Complex Numbers............................... 4-

      • Creating Complex Numbers..................... 4-



    • Infinity and NaN................................ 4-

      • Infinity..................................... 4-

      • NaN 4-



    • Identifying Numeric Classes....................... 4-

    • Display Format for Numeric Values................. 4-

      • Default Display 4-

      • Display Format Examples....................... 4-

      • Setting Numeric Format in a Program............. 4-





  • The Logical Class

    • Find Array Elements That Meet a Condition........... 5-

    • Determine if Arrays Are Logical..................... 5-

      • Identify Logical Matrix.......................... 5-

      • Test an Entire Array............................ 5-

      • Test Each Array Element........................ 5-

      • Summary Table 5-



    • Reduce Logical Arrays to Single Value.............. 5-

    • Truth Table for Logical Operations 5-



  • Characters and Strings

    • Represent Text with Character and String Arrays...... 6-

    • Create Character Arrays 6-

      • Create Character Vector......................... 6-

      • Create Rectangular Character Array................ 6-

      • Identify Characters............................. 6-

      • Work with Space Characters..................... 6-

      • Expand Character Arrays 6-



    • Create String Arrays............................. 6-

    • Cell Arrays of Character Vectors................... 6-

      • Convert to Cell Array of Character Vectors.......... 6-

      • Functions for Cell Arrays of Character Vectors....... 6-





  • Analyze Text Data with String Arrays................ 6-

  • Test for Empty Strings and Missing Values........... 6-

  • Formatting Text 6-

    • Fields of the Formatting Operator................. 6-

    • Setting Field Width and Precision................. 6-

    • Restrictions on Using Identifiers.................. 6-



  • Compare Text 6-

  • Search and Replace Text.......................... 6-

  • Convert from Numeric Values to Character Array..... 6-

    • Function Summary 6-

    • Convert Numbers to Character Codes.............. 6-

    • Represent Numbers as Text..................... 6-

    • Convert to Specific Radix....................... 6-



  • Convert from Character Arrays to Numeric Values.... 6-

    • Function Summary 6-

    • Convert from Character Code.................... 6-

    • Convert Text that Represents Numeric Values........ 6-

    • Convert from Specific Radix..................... 6-



  • Frequently Asked Questions About String Arrays...... 6-

    • Error?................................... 6- Why Does Using Command Form With Strings Return An

    • Why Do Strings in Cell Arrays Return an Error?...... 6-

    • Why Does length() of String Return 1? 6-

    • Why Does isempty("") Return 0? 6-

      • Return Multiple Strings?..................... 6- Why Does Appending Strings Using Square Brackets





  • Update Your Code to Accept Strings................ 6-

    • What Are String Arrays? 6-

      • 6- Recommended Approaches for String Adoption in Old APIs



    • How to Adopt String Arrays in Old APIs............ 6-

      • Code 6- Recommended Approaches for String Adoption in New



    • How to Maintain Compatibility in New Code......... 6-

    • How to Manually Convert Input Arguments......... 6-

      • How to Check Argument Data Types............... 6-

      • Terminology for Character and String Arrays........ 6-



    • Function Summary.............................. 6-



  • Dates and Time

    • Represent Dates and Times in MATLAB.............. 7-

    • Specify Time Zones............................... 7-

    • Convert Date and Time to Julian Date or POSIX Time 7-

    • Set Date and Time Display Format.................. 7-

      • Formats for Individual Date and Duration Arrays 7-

      • datetime Display Format........................ 7-

      • duration Display Format 7-

      • calendarDuration Display Format................. 7-

      • Default datetime Format........................ 7-



    • Generate Sequence of Dates and Time.............. 7-

      • Endpoints with Step Size..................... 7- Sequence of Datetime or Duration Values Between

      • Dates.................................... 7- Add Duration or Calendar Duration to Create Sequence of

      • Sequence................................. 7- Specify Length and Endpoints of Date or Duration

      • Sequence of Datetime Values Using Calendar Rules 7-



    • Share Code and Data Across Locales................ 7-

      • Write Locale-Independent Date and Time Code....... 7-

      • Write Dates in Other Languages 7-

      • Read Dates in Other Languages.................. 7-

      • Array........................................ 7- Extract or Assign Date and Time Components of Datetime



    • Combine Date and Time from Separate Variables 7-

    • Date and Time Arithmetic......................... 7-

    • Compare Dates and Time 7-

    • Plot Dates and Durations......................... 7-

      • Line Plot with Dates........................... 7-

      • Line Plot with Durations 7-

      • Scatter Plot with Dates and Durations............. 7-

      • Plots that Support Dates and Durations............ 7-



    • Core Functions Supporting Date and Time Arrays 7-

      • 7- Convert Between Datetime Arrays, Numbers, and Text

        • Overview................................... 7-

        • Convert Between Datetime and Character Vectors.... 7-

        • Convert Between Datetime and String Arrays........ 7-

        • Convert Between Datetime and Date Vectors........ 7-

        • Convert Serial Date Numbers to Datetime 7-

        • Convert Datetime Arrays to Numeric Values......... 7-





    • Carryover in Date Vectors and Strings............... 7-

    • Converting Date Vector Returns Unexpected Output... 7-



  • Categorical Arrays

    • Create Categorical Arrays 8-

    • Convert Text in Table Variables to Categorical......... 8-

    • Plot Categorical Data 8-

    • Compare Categorical Array Elements 8-

    • Combine Categorical Arrays....................... 8-

    • Combine Categorical Arrays Using Multiplication..... 8-

    • Access Data Using Categorical Arrays............... 8-

      • Select Data By Category........................ 8-

        • 8- Common Ways to Access Data Using Categorical Arrays





    • Work with Protected Categorical Arrays 8-

    • Advantages of Using Categorical Arrays............. 8-

      • Natural Representation of Categorical Data......... 8-

      • Mathematical Ordering for Character Vectors........ 8-

      • Reduce Memory Requirements................... 8-



    • Ordinal Categorical Arrays........................ 8-

      • Order of Categories........................... 8-

      • How to Create Ordinal Categorical Arrays 8-

      • Working with Ordinal Categorical Arrays........... 8-



    • Core Functions Supporting Categorical Arrays 8-



  • Tables

    • Create and Work with Tables....................... 9-

    • Add and Delete Table Rows........................ 9-

    • Add, Delete, and Rearrange Table Variables.......... 9-

    • Clean Messy and Missing Data in Tables............. 9-

    • Modify Units, Descriptions, and Table Variable Names. 9-

    • Add Custom Properties to Tables and Timetables..... 9-

    • Access Data in a Table............................ 9-

      • Ways to Index into a Table...................... 9-

      • Create Table from Subset of Larger Table........... 9-

      • Create Array from the Contents of Table............ 9-



    • Calculations on Tables........................... 9-





    • Create Structure Array........................... 11-

    • Access Data in a Structure Array................... 11-

    • Concatenate Structures......................... 11-

    • Generate Field Names from Variables.............. 11-

    • Access Data in Nested Structures................. 11-

    • Access Elements of a Nonscalar Struct Array 11-

    • Ways to Organize Data in Structure Arrays.......... 11-

      • Plane Organization........................... 11-

      • Element-by-Element Organization............... 11-



    • Memory Requirements for Structure Array 11-



  • Cell Arrays

    • What Is a Cell Array?............................. 12-

    • Create Cell Array................................ 12-

    • Access Data in Cell Array......................... 12-

    • Add Cells to Cell Array 12-

    • Delete Data from Cell Array...................... 12-

    • Combine Cell Arrays 12-

    • Pass Contents of Cell Arrays to Functions........... 12-

    • Preallocate Memory for Cell Array................. 12-

    • Cell vs. Structure Arrays......................... 12-

    • Multilevel Indexing to Access Parts of Cells......... 12-



  • Function Handles

    • Create Function Handle.......................... 13-

      • What Is a Function Handle? 13-

      • Creating Function Handles...................... 13-

      • Anonymous Functions.......................... 13-

      • Arrays of Function Handles..................... 13-

      • Saving and Loading Function Handles............. 13-



    • Pass Function to Another Function................. 13-

    • Call Local Functions Using Function Handles........ 13-

    • Compare Function Handles...................... 13-



  • Map Containers

    • Overview of Map Data Structure 14-

    • Description of Map Class......................... 14-

      • Properties of Map Class........................ 14-

      • Methods of Map Class......................... 14-



    • Create Map Object 14-

      • Construct Empty Map Object 14-

      • Construct Initialized Map Object................. 14-

      • Combine Map Objects.......................... 14-



    • Examine Contents of Map......................... 14-

    • Read and Write Using Key Index 14-

      • Read From Map............................. 14-

      • Add Key/Value Pairs 14-

      • Build Map with Concatenation.................. 14-



    • Modify Keys and Values in Map 14-

      • Remove Keys and Values from Map............... 14-

      • Modify Values............................... 14-

      • Modify Keys................................ 14-

      • Modify Copy of Map 14-



    • Map to Different Value Types..................... 14-

      • Map to Structure Array 14-

      • Map to Cell Array 14-





  • Combining Unlike Classes

    • Valid Combinations of Unlike Classes............... 15-

    • Combining Unlike Integer Types................... 15-

      • Overview................................... 15-

      • Example of Combining Unlike Integer Sizes......... 15-

      • Example of Combining Signed with Unsigned 15-



    • Combining Integer and Noninteger Data............ 15-

    • Combining Cell Arrays with Non-Cell Arrays......... 15-

    • Empty Matrices................................. 15-

    • Concatenation Examples.......................... 15-

      • Combining Single and Double Types............... 15-

      • Combining Integer and Double Types.............. 15-

      • Combining Character and Double Types 15-

      • Combining Logical and Double Types.............. 15-





  • Using Objects

    • Object Behavior................................. 16-

      • Two Copy Behaviors........................... 16-

      • Handle Object Copy........................... 16-

      • Value Object Copy Behavior 16-

      • Handle Object Copy Behavior 16-

      • Testing for Handle or Value Class................. 16-





  • Defining Your Own Classes

  • Scripts

    • Create Scripts.................................. 18-

    • Add Comments to Programs....................... 18-

    • Code Sections 18-

      • Divide Your File into Code Sections 18-

      • Evaluate Code Sections........................ 18-

      • Navigate Among Code Sections in a File............ 18-

      • Example of Evaluating Code Sections.............. 18-

      • Change the Appearance of Code Sections 18-

        • 18- Use Code Sections with Control Statements and Functions





    • Scripts vs. Functions 18-

    • Add Functions to Scripts......................... 18-

      • Add Local Functions.......................... 18-

      • Access Help................................ 18-

      • Run Code.................................. 18-

      • Add and Run Sections in Live Scripts............. 18-





  • Live Scripts and Functions

    • What Is a Live Script or Function?.................. 19-

      • Differences with Plain Code Scripts and Functions.... 19-

      • Requirements................................ 19-

      • Unsupported Features......................... 19-



    • Create Live Scripts in the Live Editor............... 19-

      • Create Live Script............................ 19-

      • Add Code 19-

      • Run Code................................... 19-

      • Display Output.............................. 19-

      • Format Text................................ 19-



    • Run Sections in Live Scripts 19-

      • Divide Your File Into Sections................... 19-

      • Evaluate Sections............................ 19-



    • Debug Code in the Live Editor.................... 19-

      • Show Output............................... 19-

      • Debug Using Run to Here...................... 19-

      • View Variable Value While Debugging 19-

      • Pause a Running File......................... 19-

      • End Debugging Session....................... 19-

      • Step Into Functions.......................... 19-

      • Add Breakpoints and Run...................... 19-



    • Modify Figures in Live Scripts.................... 19-

      • Explore Data............................... 19-

      • Update Code with Figure Changes............... 19-

      • Add Formatting and Annotations 19-

      • Add and Modify Multiple Subplots 19-

      • Save and Print Figure 19-





  • Format Files in the Live Editor 19-

    • Autoformatting.............................. 19-



  • Insert Equations into the Live Editor 19-

    • Insert Equation Interactively................... 19-

    • Insert LaTeX Equation 19-



  • Add Interactive Controls to a Live Script........... 19-

    • Insert Controls.............................. 19-

      • 19- Create Live Script with Multiple Interactive Controls



    • Share Live Script............................ 19-



  • Create Live Functions 19-

    • Create Live Function 19-

    • Add Code 19-

    • Add Help.................................. 19-

    • Run Live Function........................... 19-



  • Add Help for Live Functions 19-

  • Share Live Scripts and Functions.................. 19-

    • Hide Code Before Sharing..................... 19-



  • Live Code File Format (.mlx) 19-

    • Benefits of Live Code File Format................ 19-

    • Source Control 19-



  • Introduction to the Live Editor 19-

    • Editor 19- Accelerate Exploratory Programming Using the Live



  • Create an Interactive Narrative with the Live Editor 19-

    • 19- Create Interactive Course Materials Using the Live Editor



  • Create Examples Using the Live Editor............ 19-

  • Create an Interactive Form Using the Live Editor... 19-

  • Create a Real-time Dashboard Using the Live Editor 19-

Free download pdf