声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1631|回复: 1

[编程技巧] 求助,每次调用fortran函数,matlab就会崩溃

[复制链接]
发表于 2010-5-31 13:44 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

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

使用道具 举报

 楼主| 发表于 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=[1 1;2 2];b=[3 4;5 6];c=Matrixplusf(a,b)
每次都崩溃

[ 本帖最后由 sun1993 于 2010-5-31 13:51 编辑 ]
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-13 00:12 , Processed in 0.068916 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表