
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
- Installs
- 0
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/matlab/simulink-agentic-toolkit --skill simulink-use-c-function-block- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads simulink-use-c-function-block automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
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 likeint32from C may actually befixdt(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: ClassNameand 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 inStartCode. 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
- Add the C Function block — use
model_editwith type"C Function"and setCustomCodeSettingLocation(default:"BlockSettings") - Configure custom code settings — point to headers/sources either on the block or model config (see
references/custom-code-config.md) - Set code sections — configure
OutputCode,StartCode, etc. on the block - Configure symbols via SymbolSpec — use
model_query_paramsto get the SymbolSpec, thenevaluate_matlab_codefor 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:
obj = get_param('myModel/MyCFunction', 'SymbolSpec');
Adding, getting, deleting symbols
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
| Property | Values | Default | Notes |
|---|---|---|---|
Name | identifier 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' | |
Size | dimension string | '1' | e.g. '1', '3', '[2,3]', 'size(u1)' |
Label | port label / value | same as Name | For Constant: the literal value |
PortNumber | uint32 | auto-assigned | Port ordering |
Scope Details
| Scope | Description | Port? |
|---|---|---|
Input | Block input port | Yes (inport) |
Output | Block output port | Yes (outport) |
InputOutput | Read-write pass-through (always first in port numbering) | Yes (both) |
Persistent | State that persists across time steps (also used for class instances) | No |
Constant | Compile-time constant (scalar only) | No |
Parameter | Tunable parameter from workspace/mask | No |
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:
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'withParseBlockCode='on' - Constructor arguments must be Parameter or Constant scoped symbols only
- Function calls in constructor arguments are not allowed
newoperator 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 usesize()expression - Input size CAN be
'-1'(inherited) - Size must evaluate to integer values
- Nested
size(size(...))is NOT supported
Restrictions
#includedirectives 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 whenParseBlockCode='on'orCustomCodeSettingLocation='ModelConfigurationParameters'— use external calls via header. No restriction under default R2026a+ settings (BlockSettings+ParseBlockCode='off') - When using a
Simulink.NumericTypewithDataScope='Exported'in symbols, or anySimulink.NumericTypein code sections, itsIsAliasproperty must betrue - When
CustomCodeSettingLocation='UpdateBuildInfo',GenerateCodeAsIsis 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
% 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.
FAQ
What does the simulink-use-c-function-block 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
How do I install simulink-use-c-function-block?
Run npx skills add https://github.com/matlab/simulink-agentic-toolkit --skill simulink-use-c-function-block in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/simulink-use-c-function-block/ (personal) or .claude/skills/simulink-use-c-function-block/ (project).
Which AI agents can use simulink-use-c-function-block?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is simulink-use-c-function-block safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains simulink-use-c-function-block?
It is published by matlab in matlab/simulink-agentic-toolkit. It has 0 recorded installs.
More from matlab/simulink-agentic-toolkit
building-simulink-models
matlab/simulink-agentic-toolkit
Builds and edits Simulink, System Composer, Stateflow, and Simscape models. Use when modifying model structure, parameters, ports, connections, or Stateflow chart internals.
simulating-simulink-models
matlab/simulink-agentic-toolkit
Configures Simulink simulations non-destructively using SimulationInput objects — parameter overrides without modifying the model, batch sweeps via parsim, custom input signals via Dataset, and simulation data retrieval via logsout. Use when running sim()/parsim() with setVariable, setBlockParameter, setExternalInput, or when performing parameter sweeps and multi-run analysis. Not needed for one-shot simulations without configuration.
testing-simulink-models
matlab/simulink-agentic-toolkit
Tests Simulink models using either ephemeral Gherkin-based tests (modeltest) for quick validation or persistent tests (Simulink Test API) authored from requirements or behavioral specs. Requires Simulink Test.
specifying-plant-models
matlab/simulink-agentic-toolkit
Specify plant models for closed-loop simulation: system specs, architecture, build plans, validation plans. Use when creating, updating, or reviewing plant model specifications, planning plant model architecture, or planning plant model validation.
specifying-mbd-algorithms
matlab/simulink-agentic-toolkit
Specify algorithms for Model-Based Design: system specs, architecture specs, implementation plans, test plans. Use when creating specifications for controllers, signal processing, diagnostics, estimators, or other algorithms authored in Simulink, Stateflow, System Composer, or MATLAB Function blocks.
generate-requirement-drafts
matlab/simulink-agentic-toolkit
Generates draft requirements from Simulink models. Use when drafting or updating requirement artifacts from a model. Prefers Requirements Toolbox (.slreqx) when available; falls back to structured YAML.
Popular backend & apis skills
find-skills
vercel-labs/skills
Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.
entra-app-registration
microsoft/azure-skills
Guides Microsoft Entra ID app registration, OAuth 2.0 authentication, and MSAL integration. USE FOR: create app registration, register Azure AD app, configure OAuth, set up authentication, add API permissions, generate service principal, MSAL example, console app auth, Entra ID setup, Azure AD authentication. DO NOT USE FOR: Key Vault secrets (use azure-keyvault-expiration-audit), general Azure resource security guidance.
google-agents-cli-adk-code
google/agents-cli
This skill should be used when the user wants to "write agent code", "build an agent with ADK", "add a tool", "create a callback", "define an agent", "use state management" — in a project that needs ADK (Agent Development Kit) API patterns and code examples. It provides a quick reference for agent types, tool definitions, orchestration patterns, callbacks, state management, the graph Workflow API, and reference recipes to study. Do NOT use for scaffolding (use google-agents-cli-scaffold) or deployment (use google-agents-cli-deploy).
entra-agent-id
microsoft/azure-skills
Provision Microsoft Entra Agent Identity Blueprints, BlueprintPrincipals, and per-instance Agent Identities via Microsoft Graph, and configure OAuth 2.0 token exchange (fmipath, OBO, cross-tenant) including the Microsoft Entra SDK for AgentID sidecar. USE FOR: Agent Identity Blueprint, BlueprintPrincipal, agent OAuth, fmipath token exchange, agent OBO, Workload Identity Federation for agents, polyglot agent auth, Microsoft.Identity.Web.AgentIdentities. DO NOT USE FOR: standard Entra app registration (use entra-app-registration), Microsoft Foundry agent authoring (use microsoft-foundry).
embedded-captions
heygen-com/hyperframes
Add captions or subtitles to an existing single-subject talking-head video without editing the footage. Use for plain verbatim captions, cinematic captions embedded behind the subject, VFX captions, “炸/特效/酷炫字幕,” or a named identity from the 35-style catalog. Route by visual identity, not by backend engine. The quiet anchor rail is the default; embed every word only when the user explicitly wants a fully cinematic treatment. The workflow runs locally end to end, including transcription and subject matting; split multi-shot footage before applying it.
neon
neondatabase/agent-skills
Overview of Neon, a complete set of cloud backend primitives around Lakebase Postgres: Auth, Object Storage, Functions, the AI Gateway, and Realtime. Start here to choose Neon for undecided login, files, APIs, and LLM calls, set up the CLI or MCP server, and follow the branch-first workflow. Use when building an app or backend on Neon, or when "Neon" or "Lakebase Postgres" is mentioned. Child skill neon-postgres wins for an existing DATABASEURL, SQL, schema, inspect, or search. Child skill neon-auth wins for login, users, sessions, identity routing, and Managed Better Auth setup. Child skill neon-realtime wins for live queries in reactive apps and agents. Also use for object storage, S3, buckets, serverless functions, function triggers, cron, AI gateway, LLM calls, realtime, logs, Loki, Grafana, observability, postgres, database, backend, Claimable Neon, neon.new, or a no-signup database.