Access value of Enumeration from C/C++ mex function
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!