# 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 Programming Review

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

## Logical operations

**[Documentation: if,elseif,else](https://www.mathworks.com/help/matlab/ref/if.html)**

Exercise: Logical Operations

## Decision Branching

Exercise: Using if-elseif-else

The switch-case Construction

Exercise: Using switch-case

Video: For Loops

## 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

**[Exercise: Create and Call a Function](https://matlabacademy.mathworks.com/R2019a/portal.html?course=mlbe#chapter=15&lesson=2§ion=4)**

Slide: Creating Functions Files

Calling Function Files

Exercise: Compare Using a Tolerance

# Storing Heterogenous Data

## Matlab Data Types

Exercise: Creating Variables of a Specific Data Type

## Table Basics

**[Documentation: Tables](https://www.mathworks.com/help/matlab/ref/table.html)**

Exercise: Create a Table from Workspace Variables

## Extracting Data from a Table

**[Exercise: Extracting Data from a Table: Dot Notation](https://matlabacademy.mathworks.com/R2019a/portal.html?course=mlpr#chapter=2&lesson=5§ion=1)**

Exercise: Extracting Data from a Table: Curly Braces

## Cell Array Basics

**[Documentation: Cell Arrays](https://www.mathworks.com/help/matlab/ref/cell.html)**

Exercise: Creating and Concatenating Cell Arrays

Exercise: Cell Array Extraction

## Structures

**[Documentation: Structures](https://www.mathworks.com/help/matlab/ref/struct.html)**

Exercise: Create a Structure and Access Fields

Exercise: Create a Structure Array

# Structuring Heterogenous Data

## Structuring Data Considerations

Exercise: Cell Array

Exercise: Structure Array

Exercise Table

## Extracting Multiple Elements from Cell and Structure arrays

Exercise: Multiple Elements from a Cell Array

## Applying Scalar Functions to Arrays

**[Video: Applying Scalar Functions to Arrays](https://matlabacademy.mathworks.com/R2019a/portal.html?course=mlpr#chapter=3&lesson=4§ion=2)**

Exercise: Applying Functions to Groups

Exercise: cellfun Basics

## Converting Data Types

Exercise: Numeric to Cell Array

Exercise: Converting Strings

# Managing Data Efficiently

Quiz 1

Quiz 2

Video: Preallocation

Slide: Preallocating Numeric, Cell, and Structure Arrays

Exercise: Preallocation Experiment

## Nested Functions

Exercise: Create a Nested Functions

# Creating Flexible functions

## Creating Multiple Interfaces with Wrapper Functions

**[Slide: Separating the Interface from the Algorithm](https://matlabacademy.mathworks.com/R2019a/portal.html?course=mlpr#chapter=5&lesson=2§ion=1)**

Exercise: Create a Wrapper Function with a Fixed Interface

## Missing Input Arguments

Slide: Empty Input Arguments

Exercise: Skipping the Input

## Allowing Any Number of Inputs

**[Slide: Functions with a Variable Number of Inputs](https://matlabacademy.mathworks.com/R2019a/portal.html?course=mlpr#chapter=5&lesson=6§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](https://matlabacademy.mathworks.com/R2019a/portal.html?course=mlpr#chapter=5&lesson=8§ion=1)**

Exercise: Matrix or Vector Output

## Changing the Function Interface with Anonymous Functions

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

# Verifying Application Behavior

## Why Use a Testing Framework?

**[Video: Why Use a Testing Framework](https://matlabacademy.mathworks.com/R2019a/portal.html?course=mlpr#chapter=7&lesson=1§ion=1)**

## Writing and Running a Test Script

### Running a Test Script

Exercise: Run a Test Script

Exercise: Fix Broken Tests

# Utilizing Development Tools

## Code Analyzer

**[Slide: Suppressing and Fixing Code Analyzer Warnings](https://matlabacademy.mathworks.com/R2019a/portal.html?course=mlpr#chapter=8&lesson=4§ion=2)**

Exercise: Remove Code Analyzer Warnings