Simulink Use C Function Block logo

Simulink Use C Function Block

OrganizationPopular
matlab
simulink-use-c-function-block

Use when integrating legacy code, custom code, or C/C++ code into Simulink via C Function blocks. Configure Simulink C Function blocks programmatically using the SymbolSpec API. TRIGGER when the user: - Asks about calling or wrapping C/C++ code or libraries in Simulink - Wants to create, configure, or use a C Function block - Mentions integrating custom code, legacy code, or external C/C++ into a model - Asks to integrate a C++ class into a Simulink model or test bench - Mentions inputs/outputs/parameters for a C++ algorithm block

Overview

Publishermatlab
Repositorysimulink-agentic-toolkit
Skill namesimulink-use-c-function-block
Stars
1.2K
Forks
112
Bundled files
3
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 3 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by matlab on GitHub. Read the source before you install it.

Installation

Install the Simulink Use C Function Block AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/matlab/simulink-agentic-toolkit/tree/main/skills-catalog/simulink-modeling/simulink-use-c-function-block
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/matlab/simulink-agentic-toolkit.git /tmp/simulink-agentic-toolkit
mkdir -p .claude/skills
cp -r /tmp/simulink-agentic-toolkit/skills-catalog/simulink-modeling/simulink-use-c-function-block .claude/skills/simulink-use-c-function-block
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Simulink Use C Function Block in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Simulink Use C Function Block on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Simulink Use C Function Block is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

C Function Block Configuration

When to Use

  • Calling or wrapping C/C++ code or libraries in Simulink
  • Creating, configuring, or using a C Function block
  • Integrating custom code, legacy code, or external C/C++ into a model
  • Integrating a C++ class into a Simulink model or test bench
  • Configuring inputs, outputs, or parameters for a C++ algorithm in a block

When NOT to Use

  • Building general Simulink models without C/C++ integration
  • MATLAB Function blocks (Embedded MATLAB) — those use MATLAB syntax, not C/C++
  • Code generation workflows (Embedded Coder, Simulink Coder) — this skill is for simulation-time configuration only

Rules

  • Derive each symbol's Simulink type from the corresponding C/C++ function parameter/return type (e.g. float → single, bool → boolean, char*/char[] → string (R2024b+)). However, when replacing an existing block (e.g. an S-Function), use the types already on that block first — for example, what looks like int32 from C may actually be fixdt(1,32,3) or another fixed-point type in the existing model.
  • MANDATORY for C++ classes: When the user's code defines a C++ class, you MUST first attempt to declare a Persistent symbol of Class: ClassName and call class methods directly in the code sections (e.g. obj.Method(args)). If the class has an init method (not a constructor), call it in StartCode. Only fall back to wrapper/handler functions or opaque pointer patterns if the class approach fails to compile.
  • Prefer relative paths for custom code files (sources, headers, libraries, search directories). Use paths relative to the model file location (e.g. 'myFunctions.h', './src/myLib.cpp') rather than absolute paths. This ensures portability across machines and users.

Workflow Overview

  1. Add the C Function block — use model_edit with type "C Function" and set CustomCodeSettingLocation (default: "BlockSettings")
  2. Configure custom code settings — point to headers/sources either on the block or model config (see references/custom-code-config.md)
  3. Set code sections — configure OutputCode, StartCode, etc. on the block
  4. Configure symbols via SymbolSpec — use model_query_params to get the SymbolSpec, then evaluate_matlab_code for object operations

SymbolSpec API (Port & Symbol Specification)

The SymbolSpec object defines the block's inputs, outputs, persistent state, constants, and parameters.

Getting the object

Query with model_query_params, then operate via evaluate_matlab_code:

matlab
obj = get_param('myModel/MyCFunction', 'SymbolSpec');

Adding, getting, deleting symbols

matlab
symObj = obj.addSymbol('varName');       % adds with default: Input, double, size '1'
symObj = obj.getSymbol('varName');       % get one by name
allSyms = obj.Symbols;                  % get all symbols
obj.deleteSymbol('varName');

Note: addSymbol always creates with defaults (double, Input, size '1'). When re-adding a deleted symbol, explicitly set all non-default properties (Type, Scope, Size) — prior properties are not retained.

Symbol Properties

PropertyValuesDefaultNotes
Nameidentifier string(from addSymbol)Variable name in code; for class types includes constructor args
Scope'Input', 'Output', 'InputOutput', 'Persistent', 'Constant', 'Parameter''Input'See Scope Details below
Type'double', 'single', 'int8'...'uint64', 'Boolean', 'string', 'Bus: BusName', 'Enum: EnumName', 'Class: ClassName', 'AliasTypeName', or fixedpoint'double'
Sizedimension string'1'e.g. '1', '3', '[2,3]', 'size(u1)'
Labelport label / valuesame as NameFor Constant: the literal value
PortNumberuint32auto-assignedPort ordering

Scope Details

ScopeDescriptionPort?
InputBlock input portYes (inport)
OutputBlock output portYes (outport)
InputOutputRead-write pass-through (always first in port numbering)Yes (both)
PersistentState that persists across time steps (also used for class instances)No
ConstantCompile-time constant (scalar only)No
ParameterTunable parameter from workspace/maskNo

Setting Parameter values

After setting Scope to 'Parameter', set the value by configuring the block with the parameter name as the key.

C++ Class Types

Class instances are declared as Persistent scope symbols with Type = 'Class: ClassName'.

Constructor arguments are specified in the Name property:

matlab
obj = get_param('myModel/CFunction', 'SymbolSpec');

% Default constructor (no args)
sym = obj.addSymbol('myObj');
sym.Scope = 'Persistent';
sym.Type = 'Class: MyClass';

% Constructor with arguments (args must be Parameter or Constant scope symbols)
sym = obj.addSymbol('myObj(p)');
sym.Scope = 'Persistent';
sym.Type = 'Class: MyClass';

Rules for class types:

  • Class must be defined in an external header (included via custom code settings) — NOT inside code sections
  • Cannot create class instances as local variables in code sections — applies when CustomCodeSettingLocation = 'ModelConfigurationParameters' (always parsed), or 'BlockSettings' with ParseBlockCode = 'on'
  • Constructor arguments must be Parameter or Constant scoped symbols only
  • Function calls in constructor arguments are not allowed
  • new operator is not allowed when block code is parsed
  • Private/protected members cannot be accessed from code sections
  • Class type does not support save/restore (SimSnapshot)

Access class methods in code sections: y = myObj.compute(u1);

Size Expressions

  • Scalar: '1'
  • Vector: '3' or '[3,1]'
  • Matrix: '[2,3]'
  • Dynamic from input: 'size(u1)', 'size(u1,1)', 'size(u1) + 1'

Rules:

  • size() IS allowed in output dimensions (compute output size from inputs)
  • size() is NOT allowed in input dimensions
  • Output size CANNOT be '-1' (inherited) — must be explicit or use size() expression
  • Input size CAN be '-1' (inherited)
  • Size must evaluate to integer values
  • Nested size(size(...)) is NOT supported

Restrictions

  • #include directives NOT allowed inside code sections (Start/Output/Terminate) — use custom code settings
  • Start/Terminate code CANNOT access Input or Output scoped symbols
  • Constant scope must be scalar
  • Library functions (e.g. isalnum) not supported inside code sections when ParseBlockCode = 'on' or CustomCodeSettingLocation = 'ModelConfigurationParameters' — use external calls via header. No restriction under default R2026a+ settings (BlockSettings + ParseBlockCode = 'off')
  • When using a Simulink.NumericType with DataScope = 'Exported' in symbols, or any Simulink.NumericType in code sections, its IsAlias property must be true
  • When CustomCodeSettingLocation = 'UpdateBuildInfo', GenerateCodeAsIs is forced 'on'
  • Class definitions NOT allowed inside code sections — define in external header
  • Variable-size signals are not supported

Full Example: Block-Level Custom Code with C++ Function

matlab
% 1. Add C Function block with block-level custom code
%    Use model_edit: add_block type "C Function", set CustomCodeSettingLocation,
%    SimCustomHeaderFile, SimCustomSourceFile, and OutputCode on the block.

% 2. Configure symbols
obj = get_param('mMyTest/C Function', 'SymbolSpec');
obj.addSymbol('u1');
obj.addSymbol('u2');
u2obj = obj.getSymbol('u2');
u2obj.Type = 'int32';
u2obj.Size = '3';
obj.addSymbol('y');
yobj = obj.getSymbol('y');
yobj.Scope = 'Output';
yobj.Size = 'size(u2)';
obj.addSymbol('state');
stateobj = obj.getSymbol('state');
stateobj.Scope = 'Persistent';
save_system('mMyTest');
close_system('mMyTest', 0);

See references/examples.md for additional patterns (model-level custom code, C++ class with constructor args). See references/custom-code-config.md for detailed parameter tables and custom code location settings.


Copyright 2026 The MathWorks, Inc.


Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Simulink Use C Function Block AI skill do?

Use when integrating legacy code, custom code, or C/C++ code into Simulink via C Function blocks. Configure Simulink C Function blocks programmatically using the SymbolSpec API. TRIGGER when the user: - Asks about calling or wrapping C/C++ code or libraries in Simulink - Wants to create, configure, or use a C Function block - Mentions integrating custom code, legacy code, or external C/C++ into a model - Asks to integrate a C++ class into a Simulink model or test bench - Mentions inputs/outputs/parameters for a C++ algorithm block

Why use Simulink Use C Function Block on TypingMind?

Because you install it once and use it with any model. Simulink Use C Function Block is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Simulink Use C Function Block in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/matlab/simulink-agentic-toolkit/tree/main/skills-catalog/simulink-modeling/simulink-use-c-function-block. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Simulink Use C Function Block?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Simulink Use C Function Block?

As many as you like. As long as a model supports skills, you can use Simulink Use C Function Block with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Simulink Use C Function Block AI skill free?

It is published on GitHub by matlab. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇