User`s guide
Mixing M-Files and C or C++
}
mclInitializeApplication(NULL,0);
libPkgInitialize();/* Initialize library of M-Functions */
/* Create a 1-by-1 matrix containing n. */
N = mxCreateDoubleScalar(n);
/* Call mlfMrank, the compiled version of mrank.m. */
mlfMrank(1, &R, N);
/* Print the results. */
mlfPrintmatrix(R);
/* Free the matrices allocated during this computation. */
mxDestroyArray(N);
mxDestroyArray(R);
libPkgTerminate(); /* Termina te libra ry of M-functio ns */
mclTerminateApplication();
}
Explanation of mrankp.c
The heart of mrank p.c is a c all to the mlfMrank function. Most of what comes
before this call is code that creates an input argument to
mlfMrank.Most
of what comes after this call is code that displays the vector that
mlfMrank
returns. First, the code must initialize the MCR and the generated l ibPk g
library.
mclInitializeApplication(NULL,0);
libPkgInitialize(); /* Initial ize the library of M-Funct ions */
To understand how to call mlfMrank, examine its C function header, w hich is
void mlfMrank(int nargout, mxArray** r, mxArray* n);
According to the function header, mlfMrank expects on e input parameter
and returns one value. All input and output parameters are pointers to the
mxArray data type. (See the External Interfaces documentation for details
on the
mxArray data type.)
6-17