Skip to content

C and Codegen Integration

Travis Collins edited this page Jul 23, 2014 · 12 revisions

Passing data into and out of MATLAB generated C/C++ code

  1. After code has been create examine header file of function. If the function name is Function2, the resulting header file is Function2.h

Here is an example of what you should see and the original matlab function header
MATLAB:
[ output2 ] = Function2(data)

C++ Header:
extern void Function2(short data, boolean_T output2_data[], int output2_size[1]);
The above function inputs represent:

  • short data: Input to C++ generated function
  • boolean_T output2_data[]: Pointer of data that will be output
  • int output2_size[1]: Size of data that will be output

The resulting way of call or passing data into this function is the following:
int size_of_output[1];
boolean_T output[48*4];
Function2(10, output, size_of_output);

For simpler cases when the function returns just a scalar, no pointer will need to be passed for the output. The value will be simply returned as normally for other functions in C on the left side of the '=' sign.

Clone this wiki locally