C++ Math Library Reference | ![]() ![]() |
The mwArray Class
The mwArray
class public interface consists of:
See "Extracting Data from an mwArray
" in Chapter 10 of the MATLAB C++ Math Library User's Guide for documentation of the member functions GetData()
, SetData()
, ExtractScalar()
, ExtractData()
, and ToString()
.
Constructors
The mwArray
interface provides many useful constructors. You can construct an mwArray
object from the following types of data: a numerical scalar, an array of scalars, a string, an mxArray *
, or another mwArray
object.
mwArray()
Create an uninitialized array. An uninitialized array produces warnings when passed to MATLAB C++ Math Library functions. If an array is created using this default constructor, a value must be assigned to it before passing it to a MATLAB C++ Math Library function.
To create an empty double matrix that corresponds to []
in MATLAB, use the function empty()
.
mwArray(const char *str)
Create an array from a string. The constructor copies the string.
mwArray(int32 rows, int32 cols, double *real, double *imag = 0):
Create an mwArray
from either one or two arrays of double-precision floating-point numbers. If two arrays are specified, the constructor creates a complex array; both input arrays must be the same size. The data in the input arrays must be in column-major order, the reverse of C++'s usual row-major order. This constructor copies the input arrays.
Note that the last argument, imag
, is assigned a value of zero in the constructor. imag
is an optional argument. When you call this constructor, you do not need to specify the optional argument. Refer to a C++ reference guide for a more complete explanation of default arguments.
mwArray(const mwArray &mtrx)
Copy an mwArray
. This constructor is the familiar C++ copy constructor, which copies the input array. For efficiency, this routine does not actually copy the data until the data is modified. The data is referenced through a pointer until a modification occurs.
mwArray(const mxArray *mtrx)
Make an mwArray
from an mxArray *
, such as might be returned by any of the routines in the MATLAB C Math Library or the Application Program Interface Library. This routine does not copy its input array, yet the destructor frees it; therefore the input array must be allocated on the heap. In most cases, for example, with matrices returned from the Application Program Interface Library, this is the desired behavior.
mwArray(double start, double step, double stop)
Create a ramp. This constructor operates just like the MATLAB colon operator. For example, the call mwArray(1, 0.5, 3)
creates the vector[ 1, 1.5, 2, 2.5, 3 ]
.
mwArray(int32 start, int32 step, int32 stop)
mwArray(const mwSubArray & a)
Create an mwArray
from an mwSubArray
. When an indexing operation is applied to an array, the result is not another array, but an mwSubArray
object. An mwSubArray
object remembers the indexing operation. Evaluation of the operation is deferred until the result is assigned or used in another expression. This constructor evaluates the indexing operation encoded by the mwSubArray
object and creates the appropriate array.
mwArray(double)
Create a 1-by-1 mwArray
from a double-precision floating-point number.
mwArray(int)
Create an mwArray
from an integer.
![]() | Translating MATLAB Syntax into C++ Syntax | Operators | ![]() |