当调用mexFunction错误
1视图(30天)
显示旧的评论
命令行参数个数3
argv——tfError使用callFun
主要函数会导致一个错误
#包括< mex.h >
#包括< matrix.h >
#包括< stdio . h >
#包括< math.h >
#包括< h >
#包括< assert.h >
#包括< string.h >
#包括< stdlib.h >
#包括< time.h >
#包括“ants.h”
#包括“utilities.h”
#包括“InOut.h”
#包括“TSP.h”
#包括“timer.h”
#包括“ls.h”
/ / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
/ * - - -主程序- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * /
/ / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
intcallFun (int命令行参数个数,char * argv []) {
printf (“\ nargc % d”命令行参数个数);
printf (“\ nargv % s”,argv [1]);
长int我;
start_timers ();
}
/ / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
/ * - - -墨西哥人函数- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * /
/ / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
无效mexFunction (int nlhs mxArray * plhs [], int nrhs, const mxArray * prhs [])
{
int命令行参数个数= 0;
char * * argv;
int我,结果;
命令行参数个数= nrhs;
argv = (char * *) mxCalloc(命令行参数个数,sizeof (char *));
为(i = 0;我< nrhs;我+ +){
如果(! mxIsChar (prhs[我])){
mexErrMsgTxt (“char类型的输入必须。”);
返回;
}
argv[我]= mxArrayToString (prhs[我]);
}
结果= callFun(命令行参数个数,argv);
为(i = argc-1;我< = 0;我——)
mxFree (argv[我]);
mxFree (argv);
如果(结果)
mexErrMsgTxt (“主要功能引起的错误”);
}
调用函数:
callFun (“callFun”,“——特遣部队”,“tsp”,
这条线的问题是:
printf (“\ nargv % s”,argv [1]);
,但是,我不明白为什么?
0评论
接受的答案
詹姆斯Tursa
2019年9月20日
你应该得到一个编译器的警告,你callFun()函数不返回任何值,即使签名说。当你得到有趣的像这样的行为,最好是在墨西哥人命令中使用- v选项,看看所有的编译器和链接器的消息,因为他们可能会告诉你什么是错的。你应该添加这样的底部callFun()函数:
返回0;/ / <——等等价值是合适的
现在编码的方式,你的mexFunction挑选了一个垃圾值从一个注册并把它作为函数返回值。
此外,这条线
为(i = argc-1;我< = 0;我——)
应该是这个而不是
为(i = argc-1;我> = 0;我——)< = > = / /改变