External Interfaces/API    

Passing Structures and Cell Arrays

Structures and cell arrays were new data types introduced in MATLAB 5; for a discussion of the features of structures and cell arrays and the built-in functions MATLAB provides for manipulating them, refer to Structures and Cell Arrays. Like all other data types in MATLAB, structures and cell arrays can be passed into and out of C MEX-files.

Passing structures and cell arrays into MEX-files is just like passing any other data types, except the data itself is of type mxArray. In practice, this means that mxGetField (for structures) and mxGetCell (for cell arrays) return pointers of type mxArray. You can then treat the pointers like any other pointers of type mxArray, but if you want to pass the data contained in the mxArray to a C routine, you must use an API function such as mxGetData to access it.

This example takes an m-by-n structure matrix as input and returns a new 1-by-1 structure that contains these fields:

To see how this program works, enter this structure.

The results of this input are


 Passing Two or More Inputs or Outputs Handling Complex Data