当调用mexFunction错误

1视图(30天)
shdotcom shdotcom
shdotcom shdotcom 2019年9月20日
评论道: shdotcom shdotcom2019年9月21日
我已经建立的mexFunction 这个源代码 。但是,我有这个错误,当我调用的主要功能
命令行参数个数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]);
,但是,我不明白为什么?

接受的答案

詹姆斯Tursa
詹姆斯Tursa 2019年9月20日
你应该得到一个编译器的警告,你callFun()函数不返回任何值,即使签名说。当你得到有趣的像这样的行为,最好是在墨西哥人命令中使用- v选项,看看所有的编译器和链接器的消息,因为他们可能会告诉你什么是错的。你应该添加这样的底部callFun()函数:
返回0;/ / <——等等价值是合适的
现在编码的方式,你的mexFunction挑选了一个垃圾值从一个注册并把它作为函数返回值。
此外,这条线
(i = argc-1;我< = 0;我——)
应该是这个而不是
(i = argc-1;我> = 0;我——)< = > = / /改变
1评论
shdotcom shdotcom
shdotcom shdotcom 2019年9月21日
非常感谢你的帮助。有什么我能做的改善mexFunction。我用的代码 这篇文章 。然而,这段代码太老了。

登录置评。

更多的答案(0)

类别

找到更多的在从MATLAB编写C函数调用(墨西哥人文件)帮助中心文件交换

下载188bet金宝搏


释放

R2018b

社区寻宝

找到宝藏在MATLAB中央,发现社区如何帮助你!

开始狩猎!