Main Content

Handle 8-, 16-, 32-, and 64-Bit Data in C MEX File

The C Matrix API provides a set of functions that support signed and unsigned 8-, 16-, 32-, and 64-bit data. For example, the mxCreateNumericArray function constructs an unpopulated N-dimensional numeric array with a specified data size. For more information, see mxClassID.

Once you have created an unpopulated MATLAB® array of a specified data type, you can access the data using the typed data access functions, like mxGetInt8s and mxGetComplexInt8s. You can perform arithmetic on data of 8-, 16-, 32-, or 64-bit precision in MEX files. MATLAB recognizes the correct data class of the result.

The example doubleelement.c constructs a 2-by-2 matrix with unsigned 16-bit integers, doubles each element, and returns both matrices to MATLAB.

To build this example, at the command prompt type:

mex -R2017b doubleelement.c

Call the example.

ans =
     2     6
     4     8

The output of this function is a 2-by-2 matrix populated with unsigned 16-bit integers.

See Also

| | |

Related Topics