Index of Examples


Use this index to link directly to examples in the documentation.

Development Environment

Editing and Debugging M-Files

Debugging Example - The Collatz Problem

Improving M-File Performance - The Profiler

An Example Using the Profiler

Mathematics

Polynomials and Interpolation

Multidimensional Data Gridding
Triangulation and Interpolation of Scattered Data

Data Analysis and Statistics

Analyzing Residuals
Polynomial Fit
Exponential Fit
Error Bounds
Using the Basic Fitting Interface

Function Functions

Minimizing Functions of One Variable
Plotting Mathematical Functions
Computing the Length of a Curve

Differential Equations - Initial Value Problems

ODE Initial Value Problem Examples
Solving an IVP ODE in MATLAB (van der Pol Equation, Nonstiff)
The van der Pol Equation, µ = 1000 (Stiff)
Simple Nonstiff Problem
Stiff Problem (van der Pol Equation)
Finite Element Discretization
Large, Stiff Sparse Problem
Simple Event Location
Advanced Event Location
Differential-Algebraic Problem

Differential Equations - Boundary Value Problems

ODE Boundary Value Problem Examples
Mathieu's Equation
Using Continuation to Solve a Difficult BVP

Partial Differential Equations

PDE Examples
A Single PDE
Electrodynamics Problem

Sparse Matrices

Generating a Second Difference Operator

Programming and Data Types

M-File Programming

Simple Function Example
Simple Script Example
Passing Variable Numbers of Arguments
Checking the Number of Function Arguments
Accessing Single Elements of a Matrix
Accessing Multiple Elements of a Matrix
Expanding the Size of a Matrix
Deleting Rows and Columns
Concatenating Matrices
Subfunctions
Vectorizing Loops
Conversions Between Date Formats

Character Arrays (Strings)

Comparing Strings For Equality
Converting to a Cell Array of Strings
Converting Characters to Numeric Values
Creating Two-Dimensional Character Arrays
Searching and Replacing
Categorizing Characters Within a String

Multidimensional Arrays

Generating Arrays Using Indexing
Generating Arrays Using MATLAB Functions
Building Multidimensional Arrays with the cat Function
Operating on Planes and Matrices
Multidimensional Cell Arrays
Multidimensional Structure Arrays

Structures and Cell Arrays

Building Structure Arrays Using Assignment Statements
Writing Functions to Operate on Structures
Accessing Data in Structure Arrays
Building Nested Structures with the struct Function
Creating Cell Arrays
Replacing Lists of Variables with Cell Arrays
Reshaping Cell Arrays
Accessing Cell Contents Using Content Indexing
Nesting Cell Arrays
Cell Arrays of Structures

Function Handles

Constructing a Function Handle
Function File
Function Methods
Displaying Function Handle Information
Example 1 - A Simple Function Handle
Example 2 - Function Handles and Subfunctions
Converting Function Names to Function Handles
Converting Function Handles to Function Names
Simple Function Handles
Overloaded Function Handles
Constructor Function Handles
Subfunction Handles
Private Function Handles

MATLAB Classes and Objects

A Polynomial Class
How to Write subsref
Designing the Stock Class
Assets and Asset Subclasses
The Portfolio Container
Defining saveobj and loadobj for Portfolio

Graphics

Creating Specialized Plots

Stacked Bar Graphs to Show Contributing Amounts
Grouped Bar Graph
Detached 3-D Bars
Grouped 3-D Bars
Pie Chart
Comparing Datasets with Area Graphs
Overlaying Plots on Bar Graphs
Stairstep Plot of a Function
3-D Stem Plot of an FFT
Combining Stem and Line Plots
Combining Stem Plots with Line Plots
Two-Dimensional Stem Plots
Compass Plot of Wind Direction and Speed
Contour Plot of the Peaks Function
Selecting Plotting Points from the Screen
Displaying Contours in Polar Coordinates
Animating with Erase Modes
Visualizing an FFT as a Movie

Basic Printing and Exporting

Printing to a Printer Using the Defaults
Printing to a Printer Using GhostScript
Printing to a Nondefault Printer
Printing to a Printer, Setting the Size of and Centering a Figure
Printing to a Printer, Setting the Paper Size
Printing to a Printer, Locking the Ticks and Limits of the Axes
Printing to a Printer at Screen Size
Printing a Figure to a File
Exporting a Figure to the Clipboard
Exporting a Figure in EPS Format with a TIFF Preview
Exporting a Figure to a File in a Specific Graphics Format
Appending a Figure to a PostScript File

Handle Graphics Objects

Creating Graphics Objects
Copying Objects
Finding Objects
Examples - Setting Default LineStyles
Using newplot

Figure Properties

Specifying Figure Position
Two Custom Pointers

Axes Properties

Creating Axes with Specific Characteristics
Multiple Axes for Different Scaling
Placing Text Outside the Axes
Setting Tick Mark Locations
Double Axis Graphs
Changing Axis Direction
Calculating Color Limits

3-D Visualization

Creating Surface Plots

Example- Displaying Nonuniform Data on a Surface
Mapping Surface Curvature to Color
Texture Mapping a Surface

Defining the View

Dollying the Camera
Moving the Camera Through a Scene
Moving Toward or Away from the Target
axis Command Options
MATLAB Defaults
Displaying Real Objects

Lighting as a Visualization Tool

Lighting Examples
Illuminating Mathematical Functions
Positioning Lights in Data Space

Defining Patch Objects

Defining a Cube
Specifying Flat Edge and Face Coloring

Volume Visualization Techniques

Visualizing MRI Data
Slicing Fluid Flow Data
Isosurfaces in Fluid Flow Data
Adding Isocaps to an Isosurface
Stream Line Plots of Vector Data
Displaying Curl with Stream Ribbons
Displaying Divergence with Stream Tubes
Creating Stream Particle Animations
Vector Field Displayed with Cone Plots

Creating Graphical User Interfaces

Creating GUIs with MATLAB

Passing Data in the Handles Structure

Application Techniques

Launching a Dialog to Confirm an Operation
List Box Directory Reader
A GUI to Set Simulink Model Parameters
Accessing Workspace Variables from a List Box
An Address Book Reader

External Interfaces

Calling C and Fortran Programs from MATLAB

The explore Example
Examples From the Text
MEX Reference Examples
MX Examples
Engine and MAT Examples

Creating C Language MEX-Files

Passing Two or More Inputs or Outputs
Passing Strings
A First Example -- Passing a Scalar
Handling 8-,16-, and 32-Bit Data
Handling Complex Data
Passing Structures and Cell Arrays
Handling Sparse Arrays
Manipulating Multidimensional Numerical Arrays
Persistent Arrays
Calling Functions from C MEX-Files
Symmetric Indefinite Factorization Using LAPACK

Creating Fortran MEX-Files

Passing Two or More Inputs or Outputs
Passing Matrices
Passing Arrays of Strings
Passing Strings
A First Example -- Passing a Scalar
Handling Complex Data
Handling Sparse Matrices
Dynamically Allocating Memory
Calling Functions from Fortran MEX-Files

Calling MATLAB from C and Fortran Programs

Calling MATLAB From a C Application
Calling MATLAB From a Fortran Application

Calling Java from MATLAB

Finding the Public Data Fields of an Object
Concatenating Java Objects
Methodsview: Displaying a Listing of Java Methods
Creating a New Array Reference
Creating an Array of Objects within MATLAB
Creating a Copy of a Java Array
Converting to a MATLAB Structure
Converting to a MATLAB Cell Array
Passing Java Objects
Communicating Through a Serial Port
Finding an Internet Protocol Address
Reading a URL
Creating and Using a Phone Book

Importing and Exporting Data

Creating a MAT-File in C
Creating a MAT-File in Fortran
Reading a MAT-File in C
Reading a MAT-File in Fortran

ActiveX and DDE Support

Using ActiveX Collections
Writing Event Handlers
BSTR Execute([in] BSTR Command);
Using MATLAB As an Automation Client
Using Visual Basic and the MATLAB DDE Server
DDE Advisory Links

Serial Port I/O

Getting Started
Parsing Input Data Using strread
Writing and Reading Text Data
Using Events and Actions
Reading Binary Data
Connecting Two Modems
Saving and Loading
Recording Information to Disk