Using the C++ Math Library    

Getting Started

Introduction

Overview of the MATLAB C++ Math Library

Who Should Read This Book

New MATLAB C++ Math Library Features

MATLAB C++ Math Library Documentation

Getting Started Quickly

Installing the C++ Math Library

Installation with MATLAB

Installation Without MATLAB

Verifying a UNIX Installation

Verifying a PC Installation

Installing Your C++ Compiler

Building C++ Applications

Overview 

Building a Stand-Alone Application on UNIX 

Configuring the Build Environment 

Building an Application 

mbuild Options

Building a Stand-Alone Application on PCs 

Configuring the Build Environment 

Building an Application 

mbuild Options

Troubleshooting mbuild

Linking Applications Without mbuild 

Distributing Stand-Alone Applications 

Packaging the MATLAB Math Run-Time Libraries

Installing Your Application

Problem Starting Stand-Alone Application

Fundamentals

MATLAB Basics

Data Types

Operators

Functions

Input and Output

Errors

Flow of Control

MATLAB for C++ Programmers

C++ for MATLAB Users

How the Library Is Similar to MATLAB

How C++ and the Library Differ from MATLAB

MATLAB C++ Math Library Basics

Data Types

Operators

Functions

Input and Output

Errors

Memory Management

Stand-Alone Programs

Example Program: Writing Simple Functions (ex4.cpp)

Writing Efficient Programs

Learning More

Working with MATLAB Arrays

Overview

Supported MATLAB Array Types

MATLAB Array C++ Object

Numeric Arrays

Creating Numeric Arrays

Initializing a Numeric Array with Data

Example Program: Creating Arrays and Array I/O (ex1.cpp)

Sparse Matrices

Creating a Sparse Matrix

Converting a Sparse Matrix to Full Matrix Format

Evaluating Arrays for Sparse Storage

Character Arrays

Creating MATLAB Character Arrays

Cell Arrays

Creating Cell Arrays

Displaying the Contents of a Cell Array

MATLAB Structures

Creating Structures

Performing Common Array Programming Tasks

Converting Data to MATLAB Arrays

Determining Array Size

Indexing into Arrays

Overview

Terminology

Dimensions and Subscripts in MATLAB

Dimensions and Subscripts in the MATLAB C++ Math Library

Array Storage

Using One-Dimensional Subscripts

Overview

Selecting a Single Element

Selecting a Vector

Selecting a Matrix

Selecting the Entire Matrix As a Column Vector

Using N-Dimensional Subscripts

Overview

Selecting a Single Element

Selecting a Vector of Elements

Selecting a Matrix

Extending Two-Dimensional Indexing to
N Dimensions

Using Logical Subscripts

Overview

Using a Logical Matrix As a One-Dimensional Index

Using Two Logical Vectors as Indices

Using One colon() Index and One Logical Vector as Indices

Using a Scalar and a Logical Vector

Extending Logical Indexing to N Dimensions

Using Indexing in Assignment Statements

Overview

Assigning to a Single Element

Assigning to a Multiple Elements

Assigning to a Subarray

Assigning to All Elements

Extending Two-Dimensional Assignment to N Dimensions

Deleting Elements from an Array

Indexing into Cell Arrays

Overview

Referencing a Cell in a Cell Array

Referencing a Subset of a Cell Array

Referencing the Contents of a Cell

Referencing a Subset of the Contents of a Cell

Indexing Nested Cell Arrays

Assigning Values to a Cell Array

Deleting Elements from a Cell Array

Indexing into MATLAB Structure Arrays

Overview

Accessing a Field

Accessing the Contents of a Structure Field

Assigning Values to a Structure Field

Assigning Values to Elements in a Field

Referencing a Single Structure in a Structure Array

Referencing into Nested Structures

Accessing the Contents of Structures Within Cells

Deleting Elements from a Structure Array

Indexing Techniques

Duplicating a Row or Column

Concatenating Subscripts

C++ and MATLAB Indexing Syntax

The mwIndex Class

Programming Efficient Indices

Calling Library Functions

Overview

How to Call C++ Library Functions

Returning One Result and Passing Only Required Input Arguments

Passing Optional Input Arguments

Passing Optional Output Arguments

Passing Optional Input and Output Arguments

Passing Any Number of Inputs

Passing Any Number of Outputs

Summary of Library Calling Conventions

Example Program: Calling Library Functions (ex2.cpp)

How to Call Operators

Example Program: Passing Functions As Arguments (ex3.cpp)

Representing Input Arguments As a Cell Array

Using the Mathematical Operators

Overview

Using the Operators

Defining Your Own Operators

Printing, Exceptions, and Memory Management

Defining a Print Handler

Providing Your Own Print Handler

Using the Print Handler to Print Your Own Messages

Output to a GUI

Handling Exceptions

C++ Exception Handling Overview

Handling C++ Math Library Exceptions in Your Code

Example Program: Handling Exceptions (ex5.cpp)

Replacing the Default Library Error Handler

Exception Handling in the MATLAB C++ Math Library

Memory Management

Setting Up Your Own Memory Management Routines

Performance and Efficiency

The Space-Time Continuum

Array Input and Output

Overview

Using Array Stream I/O 

Overview 

Example - Array Stream I/O (ex1.cpp)  

Stream I/O Format Definitions 

Using Stream I/O to Files 

Using Streams for Interprocess Communication 

Using File I/O Functions 

Specifying Library File I/O Functions

Example - Using File I/O Functions (ex6.cpp)

Importing and Exporting MAT-File Data 

Exporting Array Data to a MAT-File

Importing Array Data from a MAT-File

Example - Using load() and save() (ex7.cpp)

Translating from MATLAB to C++

Differences Between C++ and MATLAB

Syntax

Variable Declaration

Function Calling Conventions

Control Structure

Logical Values

Name Conflicts with Standard C Library Functions

Casting an Argument to Avoid a Name Conflict

Renaming Functions to Avoid a Name Conflict

Example Program: Rewriting roots.m in C++ (ex8.cpp)

The M-File roots() Function

The C++ roots() Function

mwArray Class Interface

Introduction

Constructors

Indexing and Subscripts

Array Indexing

Cell Content Indexing

Structure Field Indexing

User-Defined Conversions

Memory Management

Operators

Array Size

Extracting Data from an mwArray

GetData( )

SetData( )

ExtractScalar( ) and ExtractData( )

ToString( )

Library Routines

Introduction

Operators

Arithmetic Operators

Relational Operators

Miscellaneous Operators

MATLAB Functions

General Purpose Commands

Operators and Special Functions

Elementary Matrices and Matrix Manipulation

Elementary Math Functions

Specialized Math Functions

Numerical Linear Algebra

Data Analysis and Fourier Transform Functions

Polynomial and Interpolation Functions

Function Functions and ODE Solvers

Character String Functions

File I/O Functions

Data Types

Time and Dates

Multidimensional Array Functions

Cell Array Functions

Structure Functions

Sparse Matrix Functions

Utility Functions

Array Access Functions

Directory Organization

Introduction

Directory Organization on UNIX

<matlab>/bin

<matlab>/extern/lib/$ARCH

<matlab>/extern/include

<matlab>/extern/include/cpp

<matlab>/extern/examples/cppmath

Directory Organization on Microsoft Windows

<matlab>\bin

<matlab>\extern\lib

<matlab>\extern\include

<matlab>\extern\include\cpp

<matlab>\extern\examples\cppmath

Exception Classes

Overview

Exception Class Descriptions

Error Messages

Overview

Error Types

Reporting Errors

Alphabetized Error Messages 


  Getting Started