有没有人遇到过这个错误信息:
未定义的函数或方法'函数名',输入参数类型为'double'。
当我编译一个mex文件时,总是出现这个错误信息。我已经仔细检查了路径,看起来应该是正确的。
这是我的代码,mex文件是amortiss.c
。
#include "mex.h"
/* The computational functions */
void arrayquotient(double input1, double input2, double output1)
{
output1=input1/input2;
}
/* The gateway function */
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
/* variable declarations here */
double input1; /* input scalar 1 */
double input2; /* input scalar 2*/
double output1; /* output scalar 1 */
/* code here */
/* get the value of the scalar input1 */
input1 = mxGetScalar(prhs[0]);
/* get the value of the scalar input2 */
input2 = mxGetScalar(prhs[1]);
/* get the value of the scalar input3 */
input3 = mxGetScalar(prhs[2]);
/* create the output scalar1 */
plhs[0] = mxCreateDoubleScalar(input1/input2);
/* get the value of the scalar output1 */
output1 = mxGetScalar(plhs[0]);
/* call the computational routines */
arrayquotient(input1,input2,output1);
}
我添加了路径(命令add path)以确保mex文件amortiss.c存在。然后我创建了一个名为arrayquotient.m的.m文件,在其中只写了我的函数声明:
function c = arrayquotient(a,b)
但是,在编译时,出现了另一个错误消息:
Error in ==> arrayquotient at 1
function c=arrayquotient(a,b)
??? Output argument "c" (and maybe others) not assigned during call to
"C:\Users\hp\Documents\MATLAB\codes_Rihab\arrayquotient.m>arrayquotient".
amortiss
还是arrayquotient
?除非你使用正确的标志进行编译,否则你编译出来的mex文件将会是amortiss
。请报告which arrayquotient -all
和which amortiss -all
的结果。 - nhowearrayquotient
中对参数output1
的赋值不会改变mexFunction
中的另一个变量output1
。如果在mexFunction
中对output1
进行赋值,仅此是不会改变plhs[0]
中的值的。您应该检查nrhs
以避免在错误输入时使Matlab崩溃。 - aschepler