Matlab Fundamentals

Workshop Overview

MATLAB is an integrated technical computing environment from the MathWorks that combines array-based numeric computation, advanced graphics and visualization, and a high-level programming language. Separately licensed toolboxes provide additional domain-specific functionality.

Participants must have a Mathworks account in order to access the links to the online tutorials in this document.

Matlab Academy:Fundamentals of Matlab

<a href=“"target="_blank">Video: Fundamentals of Matlab

<a href=“"target="_blank">Quick Reference Guide (used for presentation)

Getting Started

Entering Commands

Exercise: Order of Operations

Exercise: Valid Variable Names and Cleaning Up

Exercise: Change Output Display

Getting Data into Matlab

<a href=“"target="_blank">Video: Import Tool

Exercise: Using the Variable Editor

Exercise: Saving Modifications

Obtaing Help

<a href=“"target="_blank">Video: Using MATLAB’s Documentation

Exercise: Open and Use Function Documentation

Plotting and Common Modifications


Exercise: Plotting Gasoline Prices

Exercise: Plot Options

Annotating Plots

Exercise: Axis Labels and Title

Exercise: More Plot Annotation Options

Axis Control

Exercise: Modify Axis Properties

Exercise: Modify Gasoline Price Plot Axes

Working with Live scripts

Create and Run a Script

Exercise: Modifying and Running Scripts

Code Sections

Exercise: International Gasoline Prices

Comments and Text

Exercise: International Gasoline Prices

Creating and Manipulating Arrays

Manually Entering Arrays

Exercise: Creating Vectors

Exercise: Creating Matrices

Creating Evenly-Spaced Vectors

Exercise: Use Colon Operator and Linspace

Concatenating Arrays

Exercise: Concatenating Arrays

Exercise: Creating and Concatenating Arrays

Array Creation Functions

Exercise: Creating Arrays

Exercise: Creating Arrays of Random Numbers

Reshaping Arrays

Exercise: Reshaping a Matrix

Exercise: Overall Average Electricity Revenue

Accessing Data in Arrays

Indexing into Vectors

Exercise: Accessing and Modifying Vector Values

Exercise: Index Using Variables and Keywords

Accessing Multiple Elements

Exercise: Index with Vectors

Exercise: Modify Multiple Elements

Accessing Data in Matrices

Exercise: Row,Column Indexing

Exercise: Extract a Single Element

Exercise: Matrix Indexing with Vectors

Exercise: Extract Multiple Elements

Mathematical and Statistical Operations with Arrays

Performing Operations on Arrays

Exercise: Basic Array Arithmetic & Functionss

Video: Element-wise vs. Matrix Operations

Exercise: Element-wise Arithmetic

Exercise: Operating on Compatibly-Sized Arrays

Matrix Multiplication

Exercise: Matrix Operations

Exercise: Extract Multiple Elements

Calculating Statistics of Vectors

Exercise: Basic Statistics

Exercise: Average Gasoline Prices

Using Statistical Operations on Matrices

Exercise: Descriptive Statistics

Exercise: Statistics for Each Row

Exercise: Correlation

Visualizing Data in 2D and 3D

Identifying Available Vector Plot Types

Exercise: stairs, stem, and area

Exercise: Gasoline Prices Scatter Plot

Creating Arrays of Text

Exercise: Creating Character Arrays

Exercise: Creating Multiline Annotations

Customizing Plot Properties

Exercise: Customizing Plot Properties

Exercise: Specifying Color

Plotting Multiple Columns

Exercise: Plotting Matrix Columns

Exercise: Plotting Matrix Columns Against a Vector

Visualizing Matrices

Exercise: Surface, Mesh, and Contour

Exercise: Visualize Electricity Data

Conditional Data Selection

Logical Operations and Variables

Exercise: Logical Operations

Exercise: Logical Operations with Arrays

Exercise: Finding Winning Team Records

Counting Elements

Exercise: Count true Values in a Logical Vector

Exercise: Identify Locations of true Values

Logical Indexing

Video: Logical Indexing

Exercise: Logical Indexing

Exercise: Selecting Teams with Winning Home Record

Tables of Data

Storing Data in a Table

Exercise: Import Table Data

Exercise: Create a Table from Workspace Variables

Sorting Table Data

Exercise: Using sortrows

Extracting Portions of a Table

Exercise: Numeric Indexing

Exercise: Variable Name Indexing

Exercise: Table Indexing

Extracting Data from a Table

Exercise: Indexing with Dot Notation

Exercise: Indexing with Curly Braces

Exporting Tables

Exercise: Using writetable

Organizing Data

Combining Tables

Exercise: Concatenating Tables

Exercise: Join Tables

Table Properties

Exercise: Table Properties

Exercise: Accessing Table Properties

Indexing into Cell Arrays

Exercise: Indexing Into Cell Arrays

Exercise: Extract Multiple Elements

Working with Dates and Times

Video: Data Types for Dates and Times

Exercise: Applying Functions to Datetimes

Operating on Dates and Times

Exercise: Operating on Dates and Times

Exercise: Working with Durations

Representing Discrete Categories

Exercise: Converting to and Operating on Categoricals

Exercise: Category Names and Ordinals

Preprocessing Data

Normalizing Data

Exercise: Normalize Matrices

Exercise: Calculate Average Daily Electricity Usage

Working with Missing Data

Exercise: Ignoring NaNs in calculations

Exercise: Locating Missing Data

Exercise: Removing Rows with Missing Data

Interpolating Missing Data

Exercise: Filling Missing Values

Exercise: Interpolating Irregularly-Spaced Data

Common Data Analysis Techniques

Moving Window Operations

Exercise: Moving Average

Exercise: Smoothing Electricity Data

Linear Correlation

Exercise: Plotting Electricity Usage

Exercise: Correlations in Electricity Usage

Polynomial Fitting

Exercise: Fit a Line

Exercise: Fit a Polynomial to Electricity Usage

Programming Constructs

User Interaction

Exercise: Gathering Input

Exercise: Dialog Box Output

Decision Branching

Exercise: Using if-else

Exercise: Using if-elseif-else

Exercise: Using switch-case

Determining Size

Exercise: Using size and numel

Exercise: Using length

For Loops

Exercise: Looping Through a Vector

Exercise: Finding the Fibonacci Sequence

While Loops

Exercise: Using a While Loop

Exercise: Finding eps

Increasing Automation with Functions

Creating and Calling Functions

Exercise: Create and Call a Function

Exercise: Electricity Usage Analysis Function

Function Files

Exercise: Compare Using a Tolerance

Exercise: Custom Statistics

Function Workspaces

Quiz: Function workspaces

MATLAB Path and Calling Precedence

Exercise: MATLAB Calling Precedence

Troubleshooting Code

Code Analyzer

Exercise: Remove Code Analyzer Warnings

Debugging Run-Time Errors

Quiz: Matrix Indexing with Vectors

Additional Resources

Resources available through the MathWorks