Using the C++ Math Library    

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. This table lists the most commonly used constructors.

Table 10-1: mwArray Constructors 
Constructor
Creates
Example
mwArray()
Uninitialized array
mwArray A;
mwArray(const char *)
String array
mwArray A("MATLAB Rules");
mwArray(int32, int32,
        double*, double*)
Complex array
double real[] = { 1, 2, 3, 4 };
double imag[] = { 5, 6, 7, 8 };
mwArray A(2,2,real,imag);
mwArray(const mwArray&)
Copy of input array
mwArray A = rand(4);
mwArray B(A);
mwArray(const mxArray *)
Copy of mxArray*
mxArray *m = mlfScalar(1);
mwArray mat(m);
mwArray(double, double,
        double)
Ramp
mwArray A(1.2, 0.1, 3.5);
mwArray(int32, int32, int32)
Integer ramp
mwArray A(1, 2, 9);
mwArray(const mwSubArray&)
Array from subarray (used in indexing)
mwArray A = rand(4);
mwArray B(A(3,3));
mwArray(double)
Scalar double array
mwArray A(17.5);
mwArray(int)
Scalar integer array
mwArray A(51);

Each constructor is described below:

See Chapter 3, Working with MATLAB Arrays for more examples of how to use constructors.


 mwArray Class Interface Indexing and Subscripts