/* distfunc.c - L1 metric between samples and prototypes (c) 2004 Pavel Paclik, pavel@ph.tn.tudelft.nl $Id: distfunc.c,v 1.2 2004/03/03 13:13:23 pavel Exp $ in order to make a MEX file in Matlab use: >> mex distfunc.c -lmatlb */ #include #include #include void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { double *wp1, *wp2; double* pd; double dtemp; int fc,sc, pc; /* number of prototypes */ mxArray *arr,*arr2, *aout; /* input matrices */ int i,j,k; /* iterators */ int is_full_matrix=0; /* flag if we compute the whole sqaure matrix */ arr=(mxArray*)mlfTranspose(prhs[0]); sc=mxGetN(arr); fc=mxGetM(arr); if( nrhs == 1 ) { arr2=arr; is_full_matrix=1; /* we may compute just half of the matrix */ } else { arr2=(mxArray*)mlfTranspose(prhs[1]); } pc=mxGetN(arr2); if( fc != mxGetM(arr2) ) { mexErrMsgTxt("input matrices must have the same number of columns\n"); return; } /* if( mxGetN(prhs[nrhs-1])==mxGetM(prhs[nrhs-1]) & mxGetN(prhs[nrhs-1])==1 ) { i=(int)*mxGetPr(prhs[nrhs-1]); if(i>=0 & i<3) debug_level=i; mexPrintf(" debug_level=%d,%d ",debug_level,i); } */ /* create output distance matrix */ aout=mxCreateDoubleMatrix(sc,pc,mxREAL); pd=mxGetPr(aout); wp1=mxGetPr(arr); wp2=mxGetPr(arr2); /* mexPrintf(" %f, %f | %f, %f \n ",wp1[fc],wp1[fc+1],wp2[0],wp2[1]); */ for(i=0; i