MATLAB: Do I get a runtime error when I use the NEQ function in the MATLAB C++ Math Library

equalMATLAB C/C++ Math Libraryneqnotstandalone

Why do I get a runtime error when I use the NEQ function in the MATLAB C++ Math Library?
The following code, "example.cpp", reproduces this problem:
#include "matlab.hpp"
#include <stdlib.h> /* used for EXIT_SUCCESS */
static double xdata[] = { 1,2,3,4,5,6,7,8 };
int main(int argc, char* argv[])
{
mwArray temp1(2,4,xdata);
mwArray temp2(2,4,xdata);
mwArray z = zeros(2,4);;
// z = eq(temp1,temp2); // this works ok
z = neq(temp1,temp2); // this is BROKEN
// z = temp1 != temp2; // this works ok
// z = temp1 == temp2; // this works ok
cout <<"z: "<<z << endl;
return 0;
}
To compile and run this in MATLAB, I used the following command:
mbuild example.cpp
!example
With the code above, I would get a runtime error. However if I uncomment any other line and comment the line using NEQ, i.e.
z = eq(temp1,temp2); // this works ok
// z = neq(temp1,temp2); // this is BROKEN
// z = temp1 != temp2; // this works ok
// z = temp1 == temp2; // this works ok
The program executes correcty.

Best Answer

This is a bug in the MATLAB C++ Math Library. This has been brought to the attention of our development staff to be addressed in a future version of the C++ Math Library.
As a workaround, please use the "!=" operator for not equals instead of the functional form.