I'm using the mxCreateNumericMatrix function at my mex file:
mxArray *mxCreateNumericMatrix(mwSize m, mwSize n, mxClassID classid, mxComplexity ComplexFlag);
I want to get array of type mwSize. For that I need to determine if using mxUINT32_CLASS or mxUINT64_CLASS as classid.
I can determine it in runtime with if statement on sizeof(mwSize), but is there a more elegant way to determine the class ID of mwSize? Maybe some define that depends on the system which has one value or the other?
Just a matter of aesthetics.
BTW, at Fortran there is a function mxClassIDFromClassName: http://www.mathworks.com/help/matlab/apiref/mxclassidfromclassname.html
mwSize is used for among the other reasons, so that the mxCreateDoubleMatrix function will be portable. It is strange if no elegant solution exists for mxCreateNumericMatrix.
Edit:
As @Praetorian explained, in my case I have no reason to use the type that fits the system (32 or 64 bits), as I specifically prefer it to be 64-bit integer array, and I can define this size also in 32-bit system.
But on the other hand, I also want to return two indices to the array that I return. In my case, I know that the array itself is short, and I use uint16_T
anyway, but if I wanted it to fit the mwIndex
, I would have to use some macro (@Amro suggested some good options), because apparently, there is no function as mxCreateDoubleMatrix
for integers (that fits the system).
To sum it up, @Praetorian helped me with my case in the comments below and @Amro gave probably the best options available for the general case.