Hello,
I have a C++ code that I try to embed in Matlab using a mex function. Everything worked just fine, till I tried to hand over integers from Matlab.
Suppose I call my Mex function like:
myMexFun(0.1, 0.1, 30, 4000);
Apparently it makes a difference if I use: (1)
int a = (int)*mxGetPr(prhs[3]);
instead of defining it directly in my C++ code with: (2)
Since the first (1) expression will yield very far off wrong results.
a is used for all calculating operations (+,-,*,/) as well as an index for arrays.
Additionally I am doing the very same thing with a smaller integer for another parameter prhs[2] - (range 5-150) and with this input I do not get any issues.
What am I overseeing here?
Kind regards, and thanks for your time.
2 Comments
Jan (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/366939-mex-passing-integer-wrong-results#comment_504628
mbvoyager (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/366939-mex-passing-integer-wrong-results#comment_504644
Sign in to comment.