matlab中关闭mexfunction,使用某些数据运行mex函数时,Matlab崩溃

我编写了一个mex函数(在C中),它将2个数组和一个标量作为输入,在进行一些数学计算后,它返回一个标量作为输出 . 我可以在MATLAB平台上成功编译相应的mex函数,但是一旦我用一些输入数据运行它,就会导致MATLAB崩溃 . 错误日志的 Headers 是“在4月25日星期一检测到的分段违例...:..:.. 2016” . 我还尝试使用GNU调试器'gdb'在Linux平台上调试它 . 它显示了我使用nrhs,prhs [],nlhs,plhs []验证输入/输出参数的数量和类型的所有if语句的问题 . 例如,我检查输入参数数量的第一个语句是,

if(nrhs!=3)

mexErrMsgTxt("Error..Three inputs required.");

还有其他人为nlhs . GNU调试器将其第一个断点放在上面的if语句中,如果我正在对它进行注释,则会导致第二个if语句出现问题,同样如此 . 当我注释掉所有if语句时,mex函数成功运行并且还给出了所需的输出 .

我已经很久没有通过阅读所有可用的答案来删除这个错误,但我不能这样做 . 请帮助我解决上述问题 . 提前致谢 .

以下是实际代码:

void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])

{

double *Ip, *Is; /* Input data vectors */

double r; /* Value of r (input) */

double *dist; /* Output ImED distance */

size_t ncols; /* For storing the size of input vector */

/* Checking for proper number of arguments */

if(nrhs!=3)

mexErrMsgTxt("Error..Three inputs required.");

if(nlhs!=1)

mexErrMsgTxt("Error..Only one output required.");

/* make sure the first input argument(value of r) is scalar */

if( !mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) || mxGetNumberOfElements(prhs[0])!=1 )

mexErrMsgTxt("Error..Value of r must be a scalar.");

/* make sure that the input vectors are of type double */

if(!mxIsDouble(prhs[1]) || mxIsComplex(prhs[1]) || !mxIsDouble(prhs[2]) || mxIsComplex(prhs[2]))

mexErrMsgTxt("Error..Input vectors must be of type double.");

/* Make sure that the output is of type double and is a scalar */

if(!mxIsDouble(plhs[0]) || mxIsComplex(plhs[0]) || mxGetNumberOfElements(plhs[0])!=1)

mexErrMsgTxt("Error..Image Euclidean Distance must be a scalar.");

/* check that number of rows in input arguments is 1 */

if(mxGetM(prhs[1])!=1 || mxGetM(prhs[2])!=1)

mexErrMsgTxt("Error..Inputs must be row vectors.");

/* Get the value of r */

r = mxGetScalar(prhs[0]);

/* Getting the input vectors */

Ip = mxGetPr(prhs[1]);

Is = mxGetPr(prhs[2]);

ncols = mxGetN(prhs[1]);

/* Creating link for the scalar output */

plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);

dist = mxGetPr(plhs[0]);

imedDistCal(r,Ip,Is,(mwSize)ncols,dist);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值