sun1993 发表于 2010-5-31 13:44

求助,每次调用fortran函数,matlab就会崩溃

编写了一个MATLAB的MEX文件Matrixplusf.f90
在MATLAB下 mex Matrixplusf.f90 编译通过,没有报错
但在运行Matrixplusf 时总是出现
terminate called after throwing an instance of 'MathWorks::System::SimpleException'
Aborted
请问这个可能是什么原因造成的?谢谢

sun1993 发表于 2010-5-31 13:47

回复 楼主 sun1993 的帖子

具体的Matrixplusf.f90程序为:
subroutine mexFunction(nlhs,plhs,nrhs,prhs)
integer plhs(*),prhs(*),nlhs,nrhs
integer mxCreateDoubleMatrix,mxGetPr,mxGetM,mxGetN,mxIsNumeric
integer m1,n1,m2,n2,size
real*8 x(100),y(100),z(100)
integer x_pr,y_pr,z_pr

if (nrhs .ne. 2) then
   call mexErrMsgTxt('two input required')
elseif (nrhs .ne. 1) then
         call mexErrMsgTxt('one output required')
endif

m1=mxGetM(prhs(1))
n1=mxGetN(prhs(1))
m2=mxGetM(prhs(2))
n2=mxGetN(prhs(2))

if ((m1 .ne. m2) .or. (n1 .ne. n2)) then
      call mexErrMsgTxt('Input must be same size')
endif

size=m1*n1

plhs(1)=mxCreateDoubleMatrix(m1,n1,0)

x_pr=mxGetPr(prhs(1))
y_pr=mxGetPr(prhs(2))
z_pr=mxGetPr(plhs(1))

call mxCopyPtrToReal8(x_pr,x,size)
call mxCopyPtrToReal8(y_pr,y,size)

call matrixplus(x,y,z,m1,n1)

call mxCopyReal8ToPtr(z,z_pr,size)
return
end

subroutine matrixplus(x,y,z,m,n)
integer m,n
real*8 x(m,n),y(m,n),z(m,n)
do 20 i=1,m
    do 10 j=1,n
      z(i,j)=x(i,j)+y(i,j)
10 continue
20 continue
return
end
每个命令都仔细检查了,没发现还有什么错误
sigh~

然后在MATLAB下调用
a=;b=;c=Matrixplusf(a,b)
每次都崩溃

[ 本帖最后由 sun1993 于 2010-5-31 13:51 编辑 ]
页: [1]
查看完整版本: 求助,每次调用fortran函数,matlab就会崩溃