Download MATLAB APPLICATION DEPLOYMENT - WEB EXAMPLE GUIDE User`s guide

Transcript
4
Stand-Alone Applications
/* Print the results. */
mlfPrintMatrix(R);
/* Free the matrices allocated during this computation. */
mxDestroyArray(N);
mxDestroyArray(R);
PkgTerminate();
/* Terminate the library of M-functions */
}
An Explanation of mrankp.c
The heart of mrankp.c is a call 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 call the Compiler-generated library initialization
function.
PkgInitialize();/* Initialize the library of M-Functions */
To understand how to call mlfMrank, examine its C function header, which is
mxArray *mlfMrank(mxArray *n_rhs_)
According to the function header, mlfMrank expects one input parameter and
returns one value. All input and output parameters are pointers to the mxArray
data type. (See “External Interfaces/API” in the MATLAB online
documentation for details on the mxArray data type.) To create and manipulate
mxArray * variables in your C code, you can call the mx routines described in
the “External Interfaces/API” or any routine in the MATLAB C/C++ Math
Library. For example, to create a 1-by-1 mxArray * variable named N with real
data, mrankp calls mlfScalar:
N = mlfScalar(n);
mrankp can now call mlfMrank, passing the initialized N as the sole input
argument.
R = mlfMrank(N);
mlfMrank returns a pointer to an mxArray * variable named R. The easiest way
to display the contents of R is to call the mlfPrintMatrix convenience function:
mlfPrintMatrix(R);
4-46