Integrate External C Algorithms Using C Function Blocks

Integrate and call external C algorithms from a Simulink model

Use the C Function block to call external C code from your model. You can write output code to modify your symbols. A symbol is a variable in the code that might take input, output, persistent, parameter, or constant values in a Simulink® model. Use the C Function block to:

  • Write C code to preprocess data to call a C function. Similarly, you can write C code to postprocess data after calling a C function.

  • Specify different code for simulation and code generation.

  • Call multiple functions.

  • Initialize and work with persistent data cached in the block.

Use the C Function block in cases where you need to allocate and deallocate memory, preprocess and postprocess external code symbols, or initialize and terminate persistent data. To call simple C code, use the C Caller block. To integrate a dynamic system using C code into your Simulink model, use the S-Function block.

Blocks

C FunctionIntegrate and call external C code from a Simulink model

Objects

SymbolSpecQuery and configure C Function block data symbols
SymbolC Function block data symbol

Featured Examples