Incorrect number of arguments into mex file

조회 수: 2(최근 30일)
Hi All
I have a mex file that has worked for the last 10 years (up to R2015b) and now is giving me problems since I have upgraded my Matlab version. The problem is that I check the number of input arguments and when it is not equal to two it throws an error. When I call the mex function it now sometimes throws an error, where it does not seem to pass any arguments in. When I run through the debugger, stop at the mex function call, and then call, it seems to work. I am definitely passing in the correct arguments. The problem seems to be spurious and does not always show up. It seems to be some or other initialisation problem or something like this.
Any help would be appreciated
Etienne
  댓글 수: 3
Etienne Coetzee
Etienne Coetzee 2017년 5월 6일
Hi Philip
It is on a 64 bit machine and I mean the Matlab debugger. I will have to set up a test script and then post it. The only thing that has changed is the Matlab version. Everything else is the same. Same Fortran compiler etc.
Regards
Etienne

댓글을 달려면 로그인하십시오.

채택된 답변

James Tursa
James Tursa 2017년 5월 8일
Particularly for Fortran, you should always use the exact signature that is in the doc. Sometimes that signature changes from release to release, or maybe the default compiler options for mexing have changed. Either one of these can trip you up. E.g., look at this from your code:
SUBROUTINE MEXFUNCTION(NLHS, PLHS, NRHS, PRHS)
!
!
!$ USE OMP_LIB
IMPLICIT NONE
MWPOINTER PLHS(*), PRHS(*), mxDuplicateArray
MWSIZE NLHS, NRHS
The signature from the doc is:
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
integer nlhs, nrhs
mwPointer plhs(*), prhs(*)
You've got NLHS and NRHS typed as MWSIZE, but the signature in the doc says the type should be integer. This could be a mismatch, since MWSIZE might be defined as an integer*8 but a default integer might be an integer*4. There is no automatic type promotion in Fortran like there is in C/C++, so this might cause a problem. It would be best to type NLHS and NRHS exactly like the doc states.
  댓글 수: 2
Etienne Coetzee
Etienne Coetzee 2017년 5월 10일
James, it worked a treat. Thanks! Made my day!

댓글을 달려면 로그인하십시오.

추가 답변(0개)

범주

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by