simulink-use-c-function-block

Configure Simulink C Function blocks programmatically using the SymbolSpec API.

1.0k|98|Updated Apr 15, 2026
One-click install
npx skills add https://github.com/matlab/simulink-agentic-toolkit --skill simulink-use-c-function-block
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: simulink-use-c-function-block
Source: https://github.com/matlab/simulink-agentic-toolkit/tree/main/skills-catalog/simulink-modeling/simulink-use-c-function-block
Command: npx skills add https://github.com/matlab/simulink-agentic-toolkit --skill simulink-use-c-function-block

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Integrating legacy or custom C/C++ code into Simulink models requires correctly configuring C Function blocks, symbol scopes, data types, and custom code settings, which is error-prone when done manually. This Skill gives an AI agent the exact rules and API patterns to perform that configuration programmatically.

Core Features & Use Cases

  • SymbolSpec Configuration: Add and configure input, output, persistent, constant, and parameter symbols with correct Simulink types derived from C/C++ signatures.
  • C++ Class Integration: Declare C++ class instances as Persistent symbols with constructor arguments and call class methods directly in code sections.
  • Custom Code Settings: Configure block-level or model-level headers, sources, libraries, and search paths with portable relative paths.
  • Use Case: Wrap an existing C++ algorithm class in a Simulink test bench by adding a C Function block, declaring the class as a Persistent symbol, wiring inputs/outputs, and setting parameter values.

Quick Start

Integrate my C++ class from Adder.h into a Simulink model using a C Function block with one input, one output, and a constructor parameter.

Frequently Asked Questions about simulink-use-c-function-block

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I integrate C++ code into a Simulink model?

Add a C Function block, point it to your headers and sources via custom code settings, then configure symbols with the SymbolSpec API. C++ classes are declared as Persistent symbols with Type 'Class: ClassName' and methods are called directly in code sections.

How do I configure C Function block inputs and outputs in Simulink?

Get the block's SymbolSpec object with get_param, then use addSymbol and set each symbol's Scope, Type, and Size properties. Output sizes can use size() expressions derived from inputs, while input sizes may be inherited with '-1'.

Can a C Function block call C++ class methods?

Yes. Declare the class instance as a Persistent scope symbol with Type 'Class: ClassName', with constructor arguments in the Name property. The class must be defined in an external header, and constructor arguments must be Parameter or Constant symbols.

What MATLAB release supports block-level custom code in C Function blocks?

Block-level custom code via CustomCodeSettingLocation 'BlockSettings' was introduced in R2024a. On R2023a and R2023b, only model-level configuration through ModelConfigurationParameters is available.

Why can't I use #include inside C Function block code sections?

Code sections like OutputCode and StartCode do not accept #include directives. Headers must be specified through custom code settings such as SimCustomHeaderFile on the block or SimCustomHeaderCode at the model level.

When should I not use a C Function block?

Avoid it for MATLAB Function block logic, which uses MATLAB syntax rather than C/C++, and for code generation workflows targeting Embedded Coder. This approach covers simulation-time configuration of C/C++ integration only.