Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 工程数学软件 > MATLAB论坛
MATLAB论坛 一切MATLAB相关问题在此讨论。
回复
 
主题工具 显示模式
旧 2008-10-23, 22:14   #1
dongnan
初级会员
 
注册日期: 2008-10-23
年龄: 41
帖子: 2
声望力: 0
dongnan 正向着好的方向发展
默认 菜鸟求救一个问题

使用matlab与c混合编程时,一模一样从书上抄的例子,却总是包错
代码如下:
#include "mex.h"
#define A_IN 0
#define B_IN 1
#define C_OUT 0
#define D_OUT 1
extern void addmlt(const int MA,const int NA,const double *A,
const int MB,const int NB,const double *B,double *C,double *D)
{
int i,j,k;
for(i=0;i<MA;i++)
for(j=0;j<NA;j++){
C[i+j*MA]=A[i+j*MA]+B[i+j*MB];
}
for(i=0;i<MA;i++){
for(j=0;j<NB;j++){
D[i+j*MA]=0.0;
for(k=0;k<NA;k++){
D[i+j*MA]=D[i+j*MA]+(A[i+k*MA]*B[k+j*MB]);
}
}
}
}

void mexFunction(
int nlhs, // Number of left hand side (output) arguments
mxArray *plhs[], // Array of left hand side arguments
int nrhs, // Number of right hand side (input) arguments
const mxArray *prhs[] // Array of right hand side arguments
)
{
double *A,*B,*C,*D;
int MA,NA,MB,NB,MC,NC,MD,ND;
if(nrhs!=2)
mexErrMsgTxt("two input required");
else if(nlhs>2)
mexErrMsgTxt("too many output argument.");
if(!mxlsDouble(prhs[A_IN])||mxlsComplex(prhs[A_IN])||
!mxlsDouble(prhs[B_IN])||mxlsComplex(prhs[B_IN])){
mexErrMsgTxt("input must be double");
}

MA=mxGetM(prhs[A_IN]);
NA=mxGetN(prhs[A_IN]);
MB=mxGetM(prhs[B_IN]);
NB=mxGetN(prhs[B_IN]);
if(MA!=MB||NA!=NB)
mexErrMsgTxt("dimension of inputs should be same.");
if(NA!=MB)
mexErrMsgTxt("column of a shoulde be equal to row of b.");
MC=MA;
NC=NA;
MD=MA;
ND=NB;
plhs[C_OUT]=mxCreateDoubleMatrix(MC,NC,mxREAL);
plhs[D_OUT]=mxCreateDoubleMatrix(MD,ND,mxREAL);

A=mxGetPr(prhs[A_IN]);
B=mxGetPr(prhs[B_IN]);

C=mxGetPr(plhs[C_OUT]);
D=mxGetPr(plhs[D_OUT]);

addmlt(MA,NA,A,MB,NB,B,C,D);
}


出错误如下:
Compiling...
addmlt.c
C:\MATLAB6p5\work\addmlt\addmlt.c(44) : warning C4013: 'mxlsDouble' undefined; assuming extern returning int
C:\MATLAB6p5\work\addmlt\addmlt.c(44) : warning C4013: 'mxlsComplex' undefined; assuming extern returning int

addmlt.obj - 0 error(s), 2 warning(s)
--------------------
Linking...
Creating library addmlt.lib and object addmlt.exp
addmlt.obj : error LNK2001: unresolved external symbol _mxlsComplex
addmlt.obj : error LNK2001: unresolved external symbol _mxlsDouble
addmlt.dll : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

addmlt.dll - 3 error(s), 0 warning(s)
--------------------
求高手献玉,晚辈不胜感激/
dongnan 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码



所有时间均为北京时间。现在的时间是 12:44


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.