Re: Using MATLAB functions in C code
- From: James Tursa <aclassyguywithaknotac@xxxxxxxxxxx>
- Date: Sun, 17 Feb 2008 20:24:31 GMT
On Sun, 17 Feb 2008 18:44:02 +0000 (UTC), "dfgdfg " <AP@xxxxxxxxxxxxx>
wrote:
I'm writing a C code and I want to use fft MATLAB function.I
looked through documentation and found that
engOpen,engPutVariable and similar functions provide
interface to MATLAB engine(functions).When I tried to
compile C file wiht (mex code.c) command and error:
"undefined reference to _egOpenEngine" occured.In
documentation it is said that an lcc compiler with .bat
option files needed.The command is as follows: (lcc -f
*engoptions.bat code.c).I typed this command and everithyng
worked fine.The problem is that lcc compiler produces an
executable file.But i don't need it.I want to execute my
code from MATLAB command line like : y=Cfunc(a).
Cfunc must be written in C code and must be able to use
MATLAB fft amd ifft functions.I just want to compile them like :
mex code.c.
A simple wrapper outline to get you started. This assumes that you are
not passing anything to/from the MATLAB workspace.
James Tursa
-----------------------------------
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs,
const mxArray *prhs[])
{
int mlhs, mrhs;
mxArray *lhs[1], *rhs[3];
// Insert your C code here
// Convert your C variables to mxArray(s) rhs[0], rhs[1], rhs[2]
here
mrhs = 3;
mlhs = 1;
if( mexCallMATLAB( mlhs, lhs, mrhs, rhs, "fft") )
mexErrMsgTxt("Call to fft didn't work\n");
mxDestroyArray(rhs[0]);
mxDestroyArray(rhs[1]); // If needed
mxDestroyArray(rhs[2]); // If needed
// Convert the result lhs[0] back into a C variable
// Use your resulting C variable here
mxDestroyArray(lhs[0]); // When done with lhs[0], destory it
// Convert your C variables to mxArray(s) rhs[0], rhs[1], rhs[2]
here
mrhs = 3;
mlhs = 1;
if( mexCallMATLAB( mlhs, lhs, mrhs, rhs, "ifft") )
mexErrMsgTxt("Call to ifft didn't work\n");
mxDestroyArray(rhs[0]);
mxDestroyArray(rhs[1]); // If needed
mxDestroyArray(rhs[2]); // If needed
// Convert the result lhs[0] back into a C variable
// Use your resulting C variable here
mxDestroyArray(lhs[0]); // When done with lhs[0], destory it
}
.
- Follow-Ups:
- Re: Using MATLAB functions in C code
- From: dfgdfg
- Re: Using MATLAB functions in C code
- References:
- Using MATLAB functions in C code
- From: dfgdfg
- Using MATLAB functions in C code
- Prev by Date: Re: Grabbing LSBs of image pixels
- Next by Date: Re: Enlarging size of toolbars
- Previous by thread: Re: Using MATLAB functions in C code
- Next by thread: Re: Using MATLAB functions in C code
- Index(es):
Relevant Pages
|