matlab-deploy-embedded-ai
This skill deploys AI models to embedded hardware using MATLAB R2026a and later, covering model creation, import from PyTorch/ONNX/TensorFlow/LiteRT, verification, compression through quantization and pruning, system simulation in Simulink, and C or CUDA code generation for resource-constrained targets like ARM Cortex processors and DSPs. Use it when integrating trained neural networks into embedded systems that require code generation and hardware deployment.
git clone --depth 1 https://github.com/matlab/matlab-agentic-toolkit /tmp/matlab-deploy-embedded-ai && cp -r /tmp/matlab-deploy-embedded-ai/skills-catalog/ai-and-statistics/matlab-deploy-embedded-ai ~/.claude/skills/matlab-deploy-embedded-aiSKILL.md
# Embedded AI for Engineered Systems
Deploy AI models to embedded hardware using MATLAB® and Simulink®. This skill is
written specifically for **MATLAB R2026a** and uses APIs, functions, and workflows
introduced in that release. It covers the complete lifecycle: model creation or
import, verification, compression, system-level simulation, and code generation
for resource-constrained targets.
Requires MATLAB R2026a or newer. Core toolboxes: Deep Learning Toolbox, Statistics
and Machine Learning Toolbox, MATLAB Coder, Embedded Coder, Simulink, and
Fixed-Point Designer. Workflow-specific support packages are checked during
Environment Discovery. The MATLAB and Simulink Agentic Toolkits must be available
so the agent can drive a live MATLAB and Simulink session through MCP tools.
## When to Use
- Deploying a trained neural network (MATLAB-native or imported) to embedded hardware
- Generating C or CUDA code from a deep learning model for ARM Cortex-M/A/R, x86, or GPU targets
- Deploying imported PyTorch, ONNX, TensorFlow, or LiteRT models to embedded targets (import step handled by `/matlab-import-external-ai-model`)
- Compressing AI models (quantization, pruning, projection) to fit resource-constrained hardware
- Integrating AI inference into a Simulink system model for closed-loop simulation before code generation
- Using `loadPyTorchExportedProgram`, `importNetworkFromPyTorch`, `importNetworkFromONNX`, `importNetworkFromTensorFlow`, `dlquantizer`, `exportNetworkToSimulink`, or Embedded Coder with AI models
- Choosing between MathWorks-native code generation and direct PyTorch/LiteRT code generation
## When NOT to Use
- Training a model purely for research with no deployment target — use Deep Learning Toolbox documentation directly
- Deploying to cloud/server endpoints (no embedded target) — use MATLAB Production Server or MATLAB Compiler SDK
- Working with classical ML models (decision trees, SVMs, ensembles) that aren't neural networks — use Statistics and Machine Learning Toolbox codegen workflows directly. Note: `fitcnet`/`fitrnet` neural network models ARE covered by this skill
- Generating code for non-AI Simulink models — use standard Embedded Coder workflows
- Converting between model formats without an embedded deployment goal (e.g., ONNX to MATLAB for desktop inference only)
## Workflow Pattern Selection
This skill uses two deployment patterns:
- **Pattern 1 — MATLAB Network Codegen:** Import or build a `dlnetwork`, optionally
compress it, then generate C/C++ via MATLAB Coder or export to Simulink.
See [`references/pattern1/workflow.md`](references/pattern1/workflow.md).
- **Pattern 2 — PyTorch/LiteRT Direct Codegen:** Load a PyTorch (.pt2) or LiteRT
(.tflite) model directly and generate C/C++ without converting to a dlnetwork.
See [`references/pattern2/workflow.md`](references/pattern2/workflow.md).
### Decision Tree
Primary discriminator for external models: **deployment capabilities + hardware class**.
```
Q1: Where does the AI model come from?
|
+-- Trained in MATLAB, or requires training in MATLAB -------> Pattern 1
|
+-- External framework (PyTorch, TF, ONNX, Keras) --> Q2
|
Q2: Does the deployment need any of these?
| - Quantization (INT8 via dlquantizer)
| - Pruning or projection
| - Weight inspection / modification
| - exportNetworkToSimulink integration
|
+-- YES --> Pattern 1 (import as dlnetwork)
|
+-- NO ---> Q3
|
Q3: What is the deployment target?
|
+-- Cortex-M: Pattern 1
| (compression and Simulink verification typically needed)
|
+-- x86 / GPU:
| +-- PyTorch (.pt2) or LiteRT (.tflite) --> Pattern 2
| +-- ONNX, TF, Keras --> Pattern 1 (convert to ONNX recommended)
|
+-- Cortex-A/R:
+-- Small model --> Pattern 1
| (import as dlnetwork, then codegen)
+-- Large model:
+-- PyTorch (.pt2) or LiteRT (.tflite) --> Pattern 2
+-- ONNX, TF, Keras --> Pattern 1 (convert to ONNX recommended)
```
### Pattern Summary
| Pattern | When to Use | Primary Toolchain |
|---------|-------------|-------------------|
| **1 — MATLAB Network Codegen** | Model trained in MATLAB, OR external model needing compression/quantization/Simulink export/weight inspection, OR Cortex-M targets | MATLAB Coder™ / Embedded Coder™ |
| **2 — PyTorch/LiteRT Direct Codegen** | External PyTorch (.pt2) or LiteRT (.tflite) model on x86/GPU/Cortex-A targets; shorter path to C code without compression | MATLAB Coder™ + PyTorch & LiteRT SPKG |
Pattern 2's generated C is portable to any target, but Cortex-M deployments typically require Pattern 1 capabilities (compression, Simulink verification).
**Import step (Pattern 1):** For PyTorch/ONNX/Keras/TensorFlow model import, use `/matlab-import-external-ai-model`. This skill takes over after import for the compression, Simulink integration, and code generation phases.
### Pattern 1 vs Pattern 2 Capability Comparison
| Capability | Pattern 1 (dlnetwork) | Pattern 2 (PyTorch/LiteRT direct) |
|-----------|----------------------|----------------------|
| C code generation | Yes | Yes |
| Target: Cortex-M, Cortex-A/R, x86, GPU | Yes | Yes |
| Weight inspection / modification | **Yes** | No |
| dlquantizer (INT8) | **Yes** | No |
| Projection (compressNetworkUsingProjection) | **Yes** | No |
| Pruning | **Yes** | No |
| Simulink integration | **Yes** (exportNetworkToSimulink) | **Yes** (PyTorch SPKG Simulink blocks) |
| Combined compression | **Yes** | No |
| Speed to first C code | Slower | **Faster** |
**Rule of thumb:** Choose Pattern 1 when you need to compress, quantize, inspect
weights, or use `exportNetworkToSimulink` — or when the model is already a
`dlnetwork`, or when targeting Co>
Analyze AMS waveform data using Mixed-Signal Blockset utilities: phase noise measurement, clock jitter, anti-aliased resampling, timing measurements, lock time, INL/DNL, ADC/DAC calibration, HSpice import. Use when analyzing time-domain voltage from PLL/VCO/clock simulations, measuring phase noise from variable-step solver output, computing jitter, or resampling non-uniform data.
Analyze data using MATLAB. Use when the task involves tables, timetables, time-series data, numeric arrays, sensor matrices, or gridded data — including but not limited to exploring, filtering, sorting, cleaning, transforming, aggregating, smoothing, padding, trimming, and answering questions about data. MATLAB provides extensive, easy-to-use built-in functions for these workflows with no additional products required.
Analyze the effective toolbox file set to produce a Dependency Manifest — classify all transitive dependencies as included, product, add-on, or external-unresolved, then present resolution options with tradeoffs. Use after matlab-define-toolbox-api when the spec is approved.
S-parameters, insertion loss, fields, currents, mesh control, and solver selection for RF PCB performance validation. TRIGGER: user asks to compute S-parameters, analyze insertion/return loss, extract fields or currents, compare MoM vs FEM, or control mesh for any RF PCB component. Invoke BEFORE writing sparameters() or solver code — API is non-obvious. SKIP: designing or creating components (use the specific matlab-design-pcb-* skill), material/stackup setup only (use matlab-manage-pcb-material), optimization sweeps (use matlab-optimize-pcb-design), PDN/IR-drop analysis (use matlab-analyze-pcb-pdn).
Analyze antennas installed on electrically large conducting platforms using MATLAB Antenna Toolbox. Loads platform geometry from STL/STEP/IGES, installs antenna elements, selects electromagnetic solvers (MoM-PO, FMM, MoM), and computes patterns, impedance, coupling, and efficiency. Use when the user wants to model an antenna on a vehicle, aircraft, ship, satellite, or other large structure.
PDN DC voltage/current analysis, IR drop, design rule checking, and multi-net batch analysis on imported PCB layouts. TRIGGER: user asks about power integrity, PDN analysis, IR drop, voltage distribution, current density, power nets, or design rule checking on a PCB. Invoke BEFORE writing code — the PDN API chain is specialized and non-obvious. SKIP: importing a PCB file (use matlab-read-pcb-layout), EM field/S-parameter extraction (use matlab-analyze-em), material/stackup setup only (use matlab-manage-pcb-material), transmission line design (use matlab-design-pcb-txline).
Calculate and visualize monostatic and bistatic radar cross section (RCS) using MATLAB Antenna Toolbox. Computes RCS of platforms, antennas, and arrays with PO, MoM, and FMM solvers, supporting HH/VV/HV/VH polarization, GPU acceleration, and near-field observation. Use when the user wants to compute, plot, or analyze radar cross section.