External Interfaces Previous page   Next Page

Handling 8-,16-, and 32-Bit Data

You can create and manipulate signed and unsigned 8-, 16-, and 32-bit data from within your MEX-files. The MATLAB API provides a set of functions that support these data types. The API function mxCreateNumericArray constructs an unpopulated N-dimensional numeric array with a specified data size. Refer to the entry for mxClassID in the online reference pages for a discussion of how the MATLAB API represents these data types.

Once you have created an unpopulated MATLAB array of a specified data type, you can access the data using mxGetData and mxGetImagData. These two functions return pointers to the real and imaginary data. You can perform arithmetic on data of 8-, 16- or 32-bit precision in MEX-files and return the result to MATLAB, which will recognize the correct data class.

This example constructs a 2-by-2 matrix with unsigned 16-bit integers, doubles each element, and returns the resulting matrix to MATLAB.

At the MATLAB prompt, entering


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

Previous page  Handling Complex Data Manipulating Multidimensional Numerical Arrays Next page

© 1994-2005 The MathWorks, Inc.