Unravel.c function will not compile despite multiple attempts to debug it.
1 回表示 (過去 30 日間)
古いコメントを表示
here's the code:
/*Unravel.c*/
#include "mex.h"
void unravel(uint16_T *hx, double *link, double *x, double xsz, int hxsz)
{
int i = 15, j = 0, k = 0;
int n = 0;
while(xsz - k)
{
if (*(link + n)>0)
{
if ((*(hx + j)>>i) & 0x0001)
{
n = *(link + n);
}
else n = *(link + n) - 1;
if (i) i--; else {j++;i = 15;}
if (j > hxsz)
mexErrMsgTxt("out of code bits ???");
}
else
{
*(x + k++) = -*(link + n);
n = 0;
}
}
if (k == xsz - 1)
\
*(x + k++) = -*(link + n);
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double *link, *x, xsz;
uint16_T *hx;
int hxsz;
/*check for reasonableness*/
if(nrhs != 3)
mexErrMsgTxt("3 inputs required.");
else if (nlhs > 1)
mexErrMsgTxt("Too many output arguments");
/*is the last input a scalar*/
if (!mxIsDouble(prhs[2]) || mxIsComplex(prhs[2]) || mxGetN(prhs[2] * mxGetM(prhs[2]) != 1)
{
mexErrMsgTxt("input XSIZE must be a scalar.");
}
hx = (uint16_T *) mxGetData(prhs[0]);
link = (double *) mxGetData(prhs[1]);
xsz = mxGetScalar(prhs[2]); /* returns DOUBLE */
/* Get the number of elemnts in hx */
hxsz = mxGetM(prhs[0]);
/* Create 'xsz' x 1 output matrix */
plhs[0] = mxCreateDoubleMatrix(xsz, 1, mxREAL);
/* Get C pointer to a copy of the output matrix */
x = (double *) mxGetData(plhs[0]);
/* Call the C subroutine */
unravel(hx, link, x, xsz, hxsz);
}
}
0 件のコメント
採用された回答
Ingrid
2015 年 10 月 29 日
just going through the errors given by the mex-compiler:
you are missing a bracket on line 53, right after mxGetN(prhs[2] you are missing the closing bracket like this:
/*is the last input a scalar*/
if (!mxIsDouble(prhs[2]) || mxIsComplex(prhs[2]) || mxGetN(prhs[2]) * mxGetM(prhs[2]) != 1)
and at the end you have a } to many so just remove it and I was able to compile it just fine (this however does not guarantee your actual function will work!)
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!