matlab-generate-code

Generate, verify, and accelerate C/C++ or CUDA code from MATLAB functions using MATLAB Coder.

995|122|Updated Apr 3, 2026
One-click install
npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-generate-code
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: matlab-generate-code
Source: https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/code-generation/matlab-generate-code
Command: npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-generate-code

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Converting MATLAB algorithms into deployable C/C++ or CUDA code involves strict typing rules, codegen-incompatible language constructs, and complex configuration options that frequently cause build failures or incorrect output. This Skill guides an AI agent through the full MATLAB Coder workflow so generated code compiles, matches MATLAB behavior, and meets deployment constraints.

Core Features & Use Cases

  • Codegen-Ready Authoring: Write or review MATLAB code against code generation constraints, using coder.* directives such as coder.varsize, coder.const, coder.extrinsic, and coder.unroll.
  • Generation and Verification: Run coder.screener, generate MEX/lib/dll/exe targets, and verify numerical equivalence with coder.runTest or matlabtest.coder.TestCase, including SIL with Embedded Coder.
  • Config Tuning and Acceleration: Tune coder.config properties for embedded, speed, readability, size, or safety goals, and profile generated MEX with coder.timeit and coder.perfCompare to eliminate hotspots.
  • Use Case: A user needs to deploy a signal-processing function as a static C library with no dynamic memory. The Skill screens the function, fixes unsupported constructs with user approval, generates and verifies a MEX, then produces a DMA-off lib configuration with an appropriate StackUsageMax.

Quick Start

Ask the agent to generate C code from your MATLAB function, for example: generate a verified MEX and then a static C library from myFunction.m with double 100x1 input.

Frequently Asked Questions about matlab-generate-code

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

FAQPage Schema
How do I generate C code from a MATLAB function?

Run coder.screener to check readiness, define input types with coder.typeof, then call codegen with a coder.config target such as 'mex' or 'lib'. Verify the MEX output against MATLAB before generating standalone lib, dll, or exe targets.

How do I verify generated C code matches my MATLAB function?

Use coder.runTest with a test script containing assert statements, which replaces MATLAB calls with the MEX. If MATLAB Test is installed, use matlabtest.coder.TestCase with verifyExecutionMatchesMATLAB and AbsTol/RelTol tolerances.

Can MATLAB Coder generate code from a MATLAB class?

Yes, from R2026a use coder.ClassSignature for direct class code generation after running enableCodegenForEntryPointClasses once per session. On earlier releases, wrap class usage in an entry-point function instead.

Why does coder.screener show no output when I run it?

A bare coder.screener('func') call opens the GUI with no command-line output. Always capture the return value, then inspect res.UnsupportedCalls and res.Messages for unsupported functions and problematic constructs.

How do I generate C code without dynamic memory allocation?

Set EnableDynamicMemoryAllocation = false on the config while keeping EnableVariableSizing = true so variable-size arrays stack-allocate at their upper bound. Raise StackUsageMax, often to 512 KB or more, since worst-case arrays move to the stack.

What are the limitations of MATLAB Coder code generation?

It targets only C, C++, and CUDA, and does not support try/catch, eval, containers.Map, object arrays, or handle objects in entry-point I/O. Fixed-point conversion, Simulink Coder workflows, and hand-written MEX files are out of scope.