[問題] 在mex檔裡面可以定義function嗎?已回收
因為想要簡化程式 所以想用自定的function
不過今天試了好幾次都沒辦法把值傳入自定的function中而導致結果錯誤
想問一下是不是因為mex file並不是一個完整的FORTRAN程式
所以不能這樣作?
以下是我的mex檔
#include "fintrf.h"
C
#if 0
#endif
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
C-----------------------------------------------------------------------
C
mwpointer plhs(*), prhs(*)
mwpointer mxCreateDoubleMatrix, mxGetPr
mwpointer x_pr, y_pr
C-----------------------------------------------------------------------
C
integer nlhs, nrhs, mxIsNumeric
mwsize mxGetM, mxGetN
mwsize m, n, size
real*8 x(1000), y(1000), test
C Get the size of the input array.
m = mxGetM(prhs(1))
n = mxGetN(prhs(1))
size = m*n
C Create matrix for the return argument.
plhs(1) = mxCreateDoubleMatrix(m,n,0)
x_pr = mxGetPr(prhs(1))
y_pr = mxGetPr(plhs(1))
call mxCopyPtrToReal8(x_pr,x,size)
C Call the computational subroutine.
call matsq(y, x, m, n)
C Load the data into y_pr, which is the output to MATLAB
call mxCopyReal8ToPtr(y,y_pr,size)
return
end
subroutine matsq(y, x, m, n)
mwsize m, n, i, j
real*8 x(m,n), y(m,n)
real test
y= test(x)
return
end
C
real function test(x)
real x
test=x*2
end
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.171.35.54
→
03/01 21:50, , 1F
03/01 21:50, 1F
→
03/01 21:50, , 2F
03/01 21:50, 2F
→
03/01 21:51, , 3F
03/01 21:51, 3F
→
03/02 00:57, , 4F
03/02 00:57, 4F
MATLAB 近期熱門文章
PTT數位生活區 即時熱門文章