Querying data from enum arrays using C API
Show older comments
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 = [16x1]. 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(enumArrayField); %-> This also returns 1.
//
void *raw_data = mxGetData(enumArrayField); %->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(enumArrayField); %-> This returns 8 bytes
Accepted Answer
More Answers (0)
Categories
Find more on Simulink Functions 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!