Matlab Coder Data Types

1 view (last 30 days)
Elijah Dewey
Elijah Dewey on 27 Aug 2019
Answered: Yogesh Khurana on 16 Dec 2019
Hello,
I am trying to convert old MATLAB code from 6.5.1 to C using MATLAB Coder on 2019a. I also have old C code generated from the MATLAB code that was using Matlab Code Compiler but the data types are not listed. Is there a way to find the specific data types and lengths of array from the C code where it calls mxArray? Any help would be appreciated.

Answers (1)

Yogesh Khurana
Yogesh Khurana on 16 Dec 2019
There are various components in the generated C MEX file. Please refer to the following link for more information on the components:
mxArray is part of one of the components defined in the link above. mxArray is C type for MATLAB array. While creating mxArray, there is a need to pass the size of mxArray as well as the data-type of mxArray. Please refer to the following code that defines mxArray in on the generated C code:
int numPts = (int) mxGetNumberOfElements(prhs[0]);
mxArray * labelsMx = mxCreateNumericMatrix(numPts, 1, mxINT32_CLASS, mxREAL);
int* labels = (int*) mxGetData(labelsMx);
Here numPts is defined by passing the size through command line at the time of calling the MEX C file. mxINT32_CLASS states that the data-type of the labelsMx is int32 (MATLAB data-type). And then at the final step the labelsMx is linked to lables variable in C that is of data-type int. So, here variable “labels” is the array of data-type int and size numPts.
Please refer to the following link for more information on mxCreateNumericMatrix and mxGetData:
Hope this helps!

Categories

Find more on MATLAB Coder 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!