User`s guide
Mixing M-Files and C or C++
The program first displays the contents of a 3-by-3 matrix a,andthendisplays
the contents of scalar
b.
6.2832 +34.5575i 25.1327 +25.1327i 43.9823 +43 .9823i
12.5664 +34.5575i 31.4159 +31.4159i 50.2655 +28.2743i
18.8496 +18.8496i 37.6991 +37.6991i 56.5487 +28.2743i
143.4164
Explanation of This C Code
Invoking MATLAB Compiler on multarg. m generates the C function
prototype.
extern void mlfMultarg(int nargout, mxAr ray* * a, mxArray** b,
mxArray* x, mxArray* y);
This C function header shows two input arguments (mxArray* x and
mxArray* y) and two output arguments (the return value and mxAr ray* * b).
Use
mxCreateDoubleMatrix to create the two input matrices (x and y). Both x
and y contain real and imaginary components. The memcpy functi on initi al iz es
the components, for example:
x = mxCreateDoubleMatrix(,ROW S, COLS, mxCOMP LEX);
memcpy(mxGetPr(x), x_p r, ROWS * COLS * sizeof(double));
memcpy(mxGetPi(y), x_p i ROWS * COLS * sizeof(double));
The code in this example initializes variable x from two arrays (x_pr and
x_pi) of predefined constants. A more realistic example would read the array
values from a data file o r a database.
After creating the input matrices,
main calls mlfMultarg.
mlfMultarg(2, &a, &b, x, y);
The mlfMultarg function returns matrices a and b. a has both real and
imaginary components;
b is a scalar having only a real component. The
program uses
mlfPrintmatrix to output the matrices, for example:
mlfPrintmatrix(a);
6-21