wzyn20051216/matlab-agent-skills / skills/matlab-codegen-deploy
matlab-codegen-deploy
VerifiedMATLAB code generation and deployment workflow for MATLAB Coder, Simulink Coder, Embedded Coder, GPU Coder, HDL Coder, fixed-point conversion, MEX validation, and embedded deployment readiness. Use whenever the user asks to generate C/C++/CUDA/HDL/code, deploy algorithms, or validate generated code.
MATLAB Codegen Deploy
Use this skill when MATLAB or Simulink algorithms need to become generated code or deployable artifacts.
Skill Root
The installed directory containing this SKILL.md is the resource root. Add its
helper folder for the current MATLAB session only — never through savepath,
startup.m, or a global path edit:
skillRoot = '<absolute path to the installed matlab-codegen-deploy Skill directory>';
addpath(fullfile(skillRoot, 'scripts'));
Resolve references/, tests/, and helper calls from that root, not from the
caller's working directory. If a shipped helper or reference is missing, report the
exact path and reinstall the Skill; do not scan the disk for a substitute.
Workflow
- Identify target: MEX, C/C++, embedded C, CUDA, HDL, PLC, or packaged app.
- Verify required products with
verandlicense. - Isolate the algorithm into a codegen-friendly function.
- Define input types with
coder.typeofor representative test vectors. - Generate the smallest artifact first, usually MEX.
- Compare generated result against MATLAB golden output.
- Save generated code, logs, reports, and validation metrics.
Self-Compile and Verify Preference
The user expects generated MATLAB/Simulink work to compile and verify itself after writing. Do not stop at source generation when a build or smoke check is feasible:
- For MATLAB Coder, run
codegenand then compare generated/MEX output against MATLAB golden output when compiler support exists. - For Simulink Coder, update/compile the model first, run simulation, then call
slbuildonly after simulation passes. - For embedded targets such as STM32, first try the configured hardware target and toolchain; if it fails, capture the exact missing package/compiler message and generate the closest portable C fallback if possible.
- Verify generated
.c,.h, project, library,elf/axf/hex/bin, or fallback artifacts exist and are nonempty. - Report clearly which stage passed: model update, simulation, code generation, toolchain build, binary generation, or only portable fallback.
MATLAB Coder Pattern
Use this pattern before larger deployment:
cfg = coder.config("mex");
codegen -config cfg myFunction -args {coder.typeof(0,[100 1],[1 0])}
gold = myFunction(x);
actual = myFunction_mex(x);
assert(norm(gold-actual) < 1e-9)
Embedded Readiness
Check:
- Fixed-size vs variable-size arrays.
- Dynamic allocation and recursion.
- Unsupported functions.
- Numeric overflow and fixed-point scaling.
- Stack and heap impact.
- Timing budget and hardware target assumptions.
Simulink Codegen
For models:
- Update/compile the model after editing and before
slbuild. - Build only after simulation passes.
- Set solver and sample times explicitly.
- Run Model Advisor or relevant checks when available.
- Compare simulation outputs before and after code generation.
STM32 Embedded Coder Readiness
For STM32 targets, do not treat "an executable exists on disk" as enough. Verify the full MATLAB-to-ST chain before blaming the model:
- MATLAB products: Simulink, Simulink Coder, Embedded Coder, STM32 support package.
- MATLAB registration:
stm32cube.hwsetup.stm32Tools.getInstalledSTM32CubeMX()returns the CubeMX directory MATLAB will use. - ST tools: GNU Tools for STM32, CMSIS, CMSIS-DSP, STM32CubeMX, and the matching STM32Cube firmware package such as
STM32Cube_FW_F1_*. - Model binding: the model has a real
.iocpath inSTM32CubeMX.ProjectFile. - Target hardware:
codertarget.targethardware.getRegisteredTargetHardwareNamesincludes the required STM32 family, for exampleSTM32F1xx Based.
Prefer target data APIs over editing opaque structures:
tools = stm32cube.hwsetup.stm32Tools();
tools.updateSTM32CubeMXPath("<absolute path to the installed STM32CubeMX>");
codertarget.data.setParameterValue(model, "STM32CubeMX.ProjectFile", iocPath);
codertarget.data.setParameterValue(model, "STM32CubeMX.DeviceId", "STM32F103RBTx");
codertarget.data.setParameterValue(model, "STM32CubeMX.Family", "STM32F1");
If slbuild hangs around "Generating code from STM32CubeMX project" or "Starting compilation process":
- Check
STM32CubeMX.log, generatedhardwarescripts, and backgroundjava.exe/STM32CubeMX.exeprocesses. - Compare direct
STM32CubeMX.exe -q scriptwith MATLAB'sjava -jar STM32CubeMX.exe -q script; some CubeMX versions can behave differently. - Prefer the MathWorks-recommended CubeMX version shown by
message("stm32:setup:CubeMXReqVersion").getString. - If non-ASCII paths are involved, copy the model and
.iocto an ASCII scratch path and retry once to isolate path encoding from model errors. - Only use a local CubeMX wrapper as a documented workaround after recording the direct failure and the real CubeMX path.
Output
Report target, generated artifact path, report path, golden comparison result, and limitations.
Bundled Verification Tools
These scripts live in scripts/ and are covered by tests/test_codegen.m (11 assertions):
mas_codegen_ready(fileOrFcn)— static readiness audit before a build cycle. Reports blockers (eval/input/clear/load/containers, array growth inside a loop) separately from warnings (table/datetime/graphics/heterogeneous cells). Array growth is a blocker only inside a loop; the samex(end+1)=voutside a loop is a warning, so it is a scan, not a regex grep.mas_codegen_verify(fcn, args)— the self-compile step, made honest. It actually runscodegen, builds the MEX, runs both MATLAB and the MEX, and compares, reporting which stage failed (probe|codegen|build|run|compare). ReturnsSKIP(not PASS) when no compiler is configured.goldenFcnoption substitutes a different golden so a mismatch can be exercised on purpose — a harness that can only ever agree has not been shown to detect anything.mas_fixpt_range(fcn, stimuli)— observe output ranges under test stimuli, then measure the cost of a fixed-point representation (fraction length, SQNR, overflow fraction). Ranges are observed, not proven; the stimuli are part of the result. Without Fixed-Point Designer it returnsSKIPrather than emulatingfibadly with doubles.
Run everything with matlab -batch "test_codegen(true)" from tests/.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |