Re: errors in sample mex files?



Praetorian wrote:



Rick wrote:
I am trying to learn how to use MEX files.

I think some of Matlab's examples are wrong, which doesn't
help.

eg in file mxcalcsinglesubscript.c, part of it says:

/* Check data type of first input argument */
if (!mxIsDouble(prhs[0])) {
mexErrMsgTxt("First input argument must be a double.");
}
/* Check data type of first second argument */
if (!mxIsDouble(prhs[0]) || mxIsComplex(prhs[0])) {
mexErrMsgTxt("Second input argument must be a real double.");
}

It looks like someone hadn't finished editing the 2nd comment
heading.
Also the index to prhs in the 2nd group of statements should be
1, shouldn't it?
There are similar statements elsewhere in the file.

Either this file has multiple errors (and should never have
been
in the
distribution), or I don't understand this whole business.
please tell me - which is it?

Rick

Hi, I don't have much experience with MEX files but I''ve written a
lot
of S-Functions in C and what you say seems to be correct. The
second
input should be prhs[1].

I think the second error check is superfluous anyway. The code boils
down to this:

if(x) error();
if(x || y) error();

What's the point in testing the first condition again? I also think
the comment is plain wrong:

/* Check data type of first second argument */

What is a "first second argument"? Looks like a case of over-zealous
cutting and pasting to me.
.



Relevant Pages

  • Re: Complex If
    ... If E2 is equal to the value "Not-applicable", then it will the second condition true and hence, being an OR test, the OR function will evaluate to TRUE. ... If E2 is equal to any other value, then the first condition will be true and, again since this is an OR test, the OR function will evaluate to TRUE. ... Rick (MVP - Excel) ...
    (microsoft.public.excel.worksheet.functions)
  • Re: using between 2 numbers in a case select
    ... Rick, ... The syntax is: ... > Hi Rik ... > meet the first condition, then for the value to get to the second ...
    (microsoft.public.excel)
  • Re: Complex If
    ... any value in E2 that is not "Not-applicable" will meet the first condition and, since this is an OR, the OR function will evaluate to TRUE. ... Rick (MVP - Excel) ...
    (microsoft.public.excel.worksheet.functions)