[問題] 在mex檔裡面可以定義function嗎?已回收

看板MATLAB作者 (春風少年兄)時間16年前 (2009/03/01 17:14), 編輯推噓0(004)
留言4則, 2人參與, 最新討論串1/1
因為想要簡化程式 所以想用自定的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
少了引用hlibr.f?
03/01 21:50, 1F

03/01 21:50, , 2F
若你核心程式參數很多種,用mxGetNumberOfElements比較
03/01 21:50, 2F

03/01 21:51, , 3F
03/01 21:51, 3F

03/02 00:57, , 4F
感謝! 後來發現只要加上interface就可以以用函數了
03/02 00:57, 4F
文章代碼(AID): #19gb7n0M (MATLAB)
文章代碼(AID): #19gb7n0M (MATLAB)