Matlab & C compilation
Matlab & C compilation
(OP)
Hi,
I want some help regarding the calling of C routines in matlab(.m) files. I wrote a function in C and im calling it from a '.m' file and using its return type. My question here is as how to implement this procedure. I know a little bit about using mex, mcc in matlab but dont know exactly as how the actual procedural implementation should be. It will be a great help if you guys can please provide me some information regarding the implementation. Thanks...
I want some help regarding the calling of C routines in matlab(.m) files. I wrote a function in C and im calling it from a '.m' file and using its return type. My question here is as how to implement this procedure. I know a little bit about using mex, mcc in matlab but dont know exactly as how the actual procedural implementation should be. It will be a great help if you guys can please provide me some information regarding the implementation. Thanks...





RE: Matlab & C compilation
RE: Matlab & C compilation
RE: Matlab & C compilation
>> mex yourname.c
This creates a function you can call directly.
/* A simple MEX file to calculate column means */
#include <mex.h>
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
int row,col;
int m=mxGetM(prhs[0]), n=mxGetN(prhs[0]);
double total, *y, *x = mxGetPr(prhs[0]);
/* Special case for row vector */
if(m==1)
{
m=n;
n=1;
}
/* Create output matrix */
plhs[0] = mxCreateDoubleMatrix(1, n , mxREAL);
y = mxGetPr(plhs[0]);
/* Work Loop */
for(col=0; col<n; col++)
{
for(row=0, total=0; row<m; row++) total += *x++;
y[col] = total/m;
}
}
RE: Matlab & C compilation