Querying data from enum arrays using C API
I am passing a struct as a block dialog parameter to an S-function. The struct is deeply nested and contains some fields that are enumeration arrays. The enums are defined in matlab and inherit from Simulink.IntType. I am able to grab the data fine when the field is a scalar, as in just one element. However, if the field is an enumeration array, then I cannot. For example, I have an enumeration array that in matlab shows size = [16×1]. I have a corresponding C type array of size 16, and type of the enumeration, also defined in C. I’m confused as to how to copy the data from the enum array since I’m getting rows =1, cols = 1, and numElements = 1 when running the following code.
My code is as follows:
const char *class_name = mxGetClassName(matlabArray); -> This returns the expected enumeration type name.
mxArray *enumArrayField = mxGetField(parentField, 0, “myEnumInstanceName”);
size_t rows = mxGetM(enumArrayField); %-> This returns 1
size_t cols = mxGetN(enumArrayField); %-> This also returns 1
size_t numElements = mxGetNumberOfElements(matlabArray); %-> This also returns 1.
//
void *raw_data = mxGetData(matlabArray); %->i tried to grab the data this way but doesn’t seem to work because i cannot iterate on it
size_t element_size = mxGetElementSize(matlabArray); %-> This returns 8 bytesI am passing a struct as a block dialog parameter to an S-function. The struct is deeply nested and contains some fields that are enumeration arrays. The enums are defined in matlab and inherit from Simulink.IntType. I am able to grab the data fine when the field is a scalar, as in just one element. However, if the field is an enumeration array, then I cannot. For example, I have an enumeration array that in matlab shows size = [16×1]. I have a corresponding C type array of size 16, and type of the enumeration, also defined in C. I’m confused as to how to copy the data from the enum array since I’m getting rows =1, cols = 1, and numElements = 1 when running the following code.
My code is as follows:
const char *class_name = mxGetClassName(matlabArray); -> This returns the expected enumeration type name.
mxArray *enumArrayField = mxGetField(parentField, 0, “myEnumInstanceName”);
size_t rows = mxGetM(enumArrayField); %-> This returns 1
size_t cols = mxGetN(enumArrayField); %-> This also returns 1
size_t numElements = mxGetNumberOfElements(matlabArray); %-> This also returns 1.
//
void *raw_data = mxGetData(matlabArray); %->i tried to grab the data this way but doesn’t seem to work because i cannot iterate on it
size_t element_size = mxGetElementSize(matlabArray); %-> This returns 8 bytes I am passing a struct as a block dialog parameter to an S-function. The struct is deeply nested and contains some fields that are enumeration arrays. The enums are defined in matlab and inherit from Simulink.IntType. I am able to grab the data fine when the field is a scalar, as in just one element. However, if the field is an enumeration array, then I cannot. For example, I have an enumeration array that in matlab shows size = [16×1]. I have a corresponding C type array of size 16, and type of the enumeration, also defined in C. I’m confused as to how to copy the data from the enum array since I’m getting rows =1, cols = 1, and numElements = 1 when running the following code.
My code is as follows:
const char *class_name = mxGetClassName(matlabArray); -> This returns the expected enumeration type name.
mxArray *enumArrayField = mxGetField(parentField, 0, “myEnumInstanceName”);
size_t rows = mxGetM(enumArrayField); %-> This returns 1
size_t cols = mxGetN(enumArrayField); %-> This also returns 1
size_t numElements = mxGetNumberOfElements(matlabArray); %-> This also returns 1.
//
void *raw_data = mxGetData(matlabArray); %->i tried to grab the data this way but doesn’t seem to work because i cannot iterate on it
size_t element_size = mxGetElementSize(matlabArray); %-> This returns 8 bytes simulink, matlab, matlab coder MATLAB Answers — New Questions