Access value of Enumeration from C/C++ mex function
Show older comments
If I define an Enumeration in MATLAB as
classdef testEnum < int32
enumeration
Test0(0), ...
Test1(1)
end
end
and pass an instance of that enumeration
temp.a = testEnum.Test1;
mexEnum(temp)
to a C/C++ mex function, how do I access the integer value of the enumeration from within a C/C++ mex function?
For example compiling mexEnum.cpp with the code:
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
const int dims[2] = {1, 1};
plhs[0] = mxCreateNumericArray(2, dims, mxDOUBLE_CLASS, mxREAL);
double *temp = (double*)mxGetData(plhs[0]);
const mxArray *rhs = prhs[0];
mxArray *a = mxGetField(rhs, 0, "a");
int32_T *value = (int32_T *)mxGetData(a);
double valueDouble = (double)(*value);
*temp = valueDouble;
}
does not return the value (1) I would expect.
Accepted Answer
More Answers (0)
Categories
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!