Matlab Programming Techniques

This workhop uses selected topics from the online self-paced course from the MathWorks in the link below. Participants must have a Mathworks account in order to access the links in this document.

Matlab Academy: Matlab Programming Techniques

Matlab Programming Review

The section is a review of the basic programming constructs presented in the Matlab Fundamentals tutorial.

Logical operations

**[Documentation: if,elseif,else](**

Exercise: Logical Operations

Decision Branching

Exercise: Using if-elseif-else

The switch-case Construction

Exercise: Using switch-case

For Loops

Video: For Loops

**[Exercise: Looping Through a Vector](§ion=6)**

While Loops

To use a for loop, you need to know in advance how many iterations are required. If you want to execute a block of code repeatedly until a result is achieved, you can use a while-loop.

Slide: The while-Loop Construction

Exercise: Finding eps

Creating and Calling Functions

**[Slide: Creating and Calling Functions](§ion=1)**

**[Exercise: Create and Call a Function](§ion=4)**

Slide: Creating Functions Files

Calling Function Files

Exercise: Compare Using a Tolerance

Storing Heterogenous Data

Matlab Data Types

**[Slide: MATLAB Data Types](§ion=1)**

Exercise: Creating Variables of a Specific Data Type

Table Basics

**[Documentation: Tables](**

Exercise: Create a Table from Workspace Variables

Extracting Data from a Table

**[Exercise: Extracting Data from a Table: Dot Notation](§ion=1)**

Exercise: Extracting Data from a Table: Curly Braces

Cell Array Basics

**[Documentation: Cell Arrays](**

Exercise: Creating and Concatenating Cell Arrays

Exercise: Cell Array Extraction


**[Documentation: Structures](**

Exercise: Create a Structure and Access Fields

Exercise: Create a Structure Array

Structuring Heterogenous Data

Structuring Data Considerations

**[Slide: Structuring Data Considerations](§ion=1)**

Exercise: Cell Array

Exercise: Structure Array

Exercise Table

Extracting Multiple Elements from Cell and Structure arrays

**[Slide: Gathering Output](§ion=2)**

Exercise: Multiple Elements from a Cell Array

Exercise: Multiple Elements from a Structure Array

Function Handles

**[Using Function Handles](§ion=1)**

Exercise: Optimization

Applying Scalar Functions to Arrays

**[Video: Applying Scalar Functions to Arrays](§ion=2)**

Exercise: Applying Functions to Groups

Exercise: cellfun Basics

Converting Data Types

**[Slide: Converting Data Types](§ion=1)**

Exercise: Numeric to Cell Array

Exercise: Converting Strings

Managing Data Efficiently

**[Slide: Datatypes and Memory](§ion=1)**

Quiz 1

Quiz 2

Video: Preallocation

Slide: Preallocating Numeric, Cell, and Structure Arrays

Exercise: Preallocation Experiment


Copy-on-write with Function Parameters

**[Slide: Copy-on-write Behavior](§ion=1)**

In-place Optimizations

**[Slide: In-place Optimizations](§ion=1)**

Nested Functions

**[Slide: Nested Functions](§ion=2)**

Exercise: Create a Nested Functions

Creating Flexible functions

**[Video: Creating Flexible Function Interfaces](§ion=1)**

Creating Multiple Interfaces with Wrapper Functions

**[Slide: Separating the Interface from the Algorithm](§ion=1)**

Exercise: Create a Wrapper Function with a Fixed Interface

Setting Default Input Values

**[Slide: Setting Default Input Values](§ion=1)**

Missing Input Arguments

**[Slide: Missing Input Arguments](§ion=2)**

Slide: Empty Input Arguments

Exercise: Skipping the Input

Allowing Any Number of Inputs

**[Slide: Functions with a Variable Number of Inputs](§ion=1)**

Slide: Variable Length Input Argument List

Slide: Passing Argument Lists to Another Function

Allowing a Variable Number of outputs

**[Slide: Defining Different Behaviors Based on Outputs](§ion=1)**

Exercise: Matrix or Vector Output

Changing the Function Interface with Anonymous Functions

**[Slide: Modifying Function Interfaces](§ion=1)**

Slide: Wrapping Functions with Anonymous Functions

Exercise: Write and Use an Anonymous Function

Slide: Common Function Handle Uses

Exercise: Change Function Interface with an Anonymous Function

Creating Robust Applications

Restricting Access Using Private Functions

**[Slide: Making Functions Private](§ion=2)**

Writing Local Functions

Comparison of Functions

**[Exercise: Create Local Functions](§ion=4)**

Validating Function Inputs


Verifying Application Behavior

Why Use a Testing Framework?

**[Video: Why Use a Testing Framework](§ion=1)**

What is a Test

**[Slide: Elements of a Test](§ion=1)**

is Functions

**[Exercise: isequal Versus ==](§ion=3)**

Test Response

**[Exercise: assert](§ion=5)**

Writing and Running a Test Script

Writing a Test Script

**[Exercise: Write a Test Script](§ion=3)**

Running a Test Script

**[Slide: Running a Test Script](§ion=4)**

Exercise: Run a Test Script

Exercise: Fix Broken Tests

Utilizing Development Tools

Developing and Maintaining Code

Folder Reports

**[Slide: Folder Reports](§ion=2)**

Errors and Debugging

**[Video: Different Kinds of Errors](§ion=1)**

Code Analyzer

**[Slide: Suppressing and Fixing Code Analyzer Warnings](§ion=2)**

Exercise: Remove Code Analyzer Warnings

Debugging Runtime Errors

**[Slide: Debugging Run-Time Errors](§ion=3)**

Measuring Performance

**[Slide: Tic and Toc](§ion=2)**

Finding Bottlenecks

**[Video: The MATLAB Profiler](§ion=2)**