aaaa.f

来自「matlab从入门到精通第13章书后源码对初学者很有帮助」· F 代码 · 共 40 行

F
40
字号
 subroutine test(x,y,z,out1,out2)
 real *8 x,y,z,out1,out2
 out1=x+y+z
 out2=x*y*z
 return
 end
 subroutine mexfunction(nlhs,plhs,nrhs,prhs)
 integer plhs(*),prhs(*)
 integer xp,yp,zp,pout1,pout2
 integer nlhs,nrhs,m,n,size
 integer mxGetPr,mxCopyPtrTo,mxCreateFull
 integer mxGetM,mxGetN
 real *8 x,y,z,out1,out2
 if (nlhs.ne.2) then
  call mexerrmsgtxt('require 2 output arg')
 endif
 if (nrhs.ne.3) then
  call mexerrmsgtxt('require 3 input arg')
 endif
 m=mxGetM(prhs(1))
 n=mxGetN(prhs(1))
 size=m*n
 plhs(1)=mxCreateFull(m,n,0)
 plhs(2)=mxCreateFull(m,n,0)
 xp=mxGetPr(prhs(1))
 yp=mxGetPr(prhs(2))
 zp=mxGetpr(prhs(3))
 call mxcopyptrtoreal8(xp,x,size)
 call mxcopyptrtoreal8(yp,y,size)
 call mxcopyptrtoreal8(zp,z,size)
 pout1=mxGetPr(plhs(1))
 pout2=mxGetPr(plhs(2))
 call test(x,y,z,out1,out2)
 call mxcopyreal8toptr(out1,pout1,size)
 call mxcopyreal8toptr(out2,pout2,size)
 return
 end
 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?