Using the C++ Math Library | ![]() ![]() |
Data Types
Arrays are represented by objects of the class mwArray
. However, unlike MATLAB, C++ allows numbers like 17 to be declared integers rather than 1-by-1 arrays, at a considerable savings in space and increased speed. All the routines in the MATLAB C++ Math Library can handle integers, double-precision floating-point numbers, or strings as easily as arrays. C++ automatically converts the scalars or strings into arrays before the routines are called.
Every mwArray
class object contains a pointer to a MATLAB array structure. For this reason, the attributes of an mwArray
object are a superset of the attributes of a MATLAB array. Every MATLAB array contains information about the size and shape of the array (i.e., the number of rows, columns, and pages) and either one or two arrays of data. The first array stores the real part of the array data and the second array stores the imaginary part. For arrays with no imaginary part, the second array is not present. The data in the array is arranged in column-major, rather than row-major, order.
The mwArray
class has a small interface. Most of the functions in the MATLAB C++ Math Library are not members of the mwArray
class. Having a small interface means that mwArray
is an easy class to understand and one that is less likely to change as the library grows. Chapter 10 describes the interface completely.
The MATLAB C++ Math Library defines two other important data types: mwIndex
and mwSubArray
. Both of these classes are used by the array indexing routines. mwIndex
objects represent the index applied to the array and mwSubArray
objects represent the subscripting operation itself. Casual users of the library won't need to use these two classes. See The mwIndex Class in Chapter 4 for complete details.
You can make an mwArray
from any number of other data types: integers, double-precision floating-point real numbers, strings (delimit C++ strings with ""
rather than ''
), an instance of an mwIndex
or mwSubArray
. Like the routines in MATLAB, most of the operators and function calls in the MATLAB C++ Math Library return a newly allocated array.
![]() | MATLAB C++ Math Library Basics | Operators | ![]() |