#include "mex.h" int mexCallMATLAB(nlhs,plhs,nrhs,prhs,name) int nlhs; Matrix *plhs[];
int nrhs; Matrix *prhs[];
char *name;
integer*4 function mexCallMATLAB(nlhs,plhs,nrhs,prhs,name)
integer*4 nlhs,nrhs,plhs(
*),prhs(
*)
character*(
*) name
name
nlhs
nrhs
plhs
prhs
mexFunction
for a complete description of the arguments.
MATLAB operators (such as Matrix multiplication, division, addition, etc.) are referenced by strings containing the operator symbols
* / +
.
This routine allocates new Matrix structures each time it is called, so it is important to return them using mxFreeMatrix
when necessary.
If an error is encountered within the call to MATLAB, the default response is for this routine to never return and for the program to longjmp out of the MEX-file, returning control directly to the MATLAB prompt. The routine mexSetTrapFlag
can be used to disable this response to errors. In this case, mexCallMATLAB
returns zero if the operation is successful and a nonzero value if an error is encountered.
mexCallMATLAB
. The example generates and prints a Matrix, computes its eigenvalues and eigenvectors, and prints out the eigenvalue Matrix.
/*A Fortran version of this is inmextest1.c
*/
int m, n, mn, mrhs, mlhs; Matrix *lhs[2],
*x;
m = n = 4; x = mxCreateFull(m,n,IMAG); /*Fill matrix with data and print it out
*/
fill(mexGetPr(x), mexGetPi(x)); mrhs = 1; mlhs = 0; mexCallMATLAB(mlhs,lhs,mrhs,&x,"disp"); /*calculate eigenvalues and eigenvectors
*/
mlhs = 2; mexCallMATLAB(mlhs,lhs,mrhs,&x,"eig"); /*print out eigenvalue matrix
*/
mlhs = 0; mexCallMATLAB(mlhs,lhs,mrhs,&lhs[1],"disp"); /*Free allocated matrices
*/
mxFreeMatrix(x); mxFreeMatrix(lhs[1]); mxFreeMatrix(lhs[0]);
mextest1.f
.(c) Copyright 1994 by The MathWorks, Inc.