matlab/matlab-deploy-embedded-ai
> Deploy AI models to embedded hardware using MathWorks tools (MATLAB, Simulink, models rebuilt as dlnetwork for lean hardware, (2) direct C/C++ code generation from PyTorch and LiteRT models. Both patterns support all targets (Cortex-M/A/R, x86, GPU). neural networks; compress AI models for MCU; integrate AI in Simulink for system-level simulation; import PyTorch/ONNX/TensorFlow models for embedded deployment; optimize AI for resource-constrained hardware; or use loadPyTorchExportedProgram, loadLiteRTModel, importNetworkFromPyTorch, importNetworkFromONNX, importNetworkFromTensorFlow, importNetworkFromKeras, dlquantizer, exportNetworkToSimulink, or Embedded Coder with AI models.
npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-deploy-embedded-ai
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.
/matlab-import-external-ai-model)loadPyTorchExportedProgram, importNetworkFromPyTorch, importNetworkFromONNX, importNetworkFromTensorFlow, dlquantizer, exportNetworkToSimulink, or Embedded Coder with AI modelsfitcnet/fitrnet neural network models ARE covered by this skillThis skill uses two deployment patterns:
dlnetwork, optionallycompress it, then generate C/C++ via MATLAB Coder or export to Simulink.
See references/pattern1/workflow.md.
(.tflite) model directly and generate C/C++ without converting to a dlnetwork.
See references/pattern2/workflow.md.
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 | 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.
| 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 Cortex-M. Choose Pattern 2 when the model is already
in PyTorch (.pt2) or LiteRT (.tflite) format and you want the shorter path to C code
without compression.
Stats/ML models (fitrnet/fitcnet): These follow Pattern 1 but have their own
Simulink integration path. Use the RegressionNeuralNetwork Predict block (for
fitrnet) or ClassificationNeuralNetwork Predict block (for fitcnet) from
the Statistics and Machine Learning Toolbox library — do NOT use
exportNetworkToSimulink (which is for dlnetwork only). Configure simulation
programmatically with Simulink.SimulationInput.
Regardless of pattern, always begin with these two prerequisite steps before
entering the pattern-specific phases (which start at Phase 1):
references/shared/environment-setup.mdreferences/shared/project-discovery.mdProject Discovery determines the workflow pattern via the decision tree above.
| Legacy | Modern Replacement |
|--------|-------------------|
| trainNetwork / train (for DL) | trainnet |
| DAGNetwork / SeriesNetwork / network | dlnetwork |
| taylorPrunableNetwork / updateScore / updatePrunables | compressNetworkUsingTaylorPruning (when trainable with trainnet); use taylorPrunableNetwork for custom training loops |
| csvread / xlsread | readmatrix / readtable |
| datenum | datetime |
For legacy import functions (importONNXNetwork, importKerasNetwork, etc.), see
/matlab-import-external-ai-model which handles all model import workflows.
Distinguish between two modes based on the user's intent:
the routing question directly — state the recommended Pattern, explain why, and outline
the high-level steps. Do NOT enter Environment Discovery or start asking prerequisite
questions. After giving the recommendation, ask if the user wants to begin execution.
prerequisite flow (Environment Discovery → Project Discovery → step-by-step phases).
detect_matlab_toolboxes and support packages via matlabshared.supportpkg.getInstalled before any workflow stepsingle precision for all inference inputs.m script file and execute it with run_matlab_file or evaluate_matlab_code. Do NOT run ad-hoc MATLAB commands without first writing the script file. If a script needs changes, edit the script file and re-run it. This gives users full visibility into what code is being executed and enables reproducibility. IMPORTANT: run_matlab_file sets the working directory to the script's folder. Always use absolute paths (via fullfile) for model files, data, and saved outputs — never rely on pwd or relative paths.deepNetworkDesigner(net)) so the user can visually inspect the architecture. Announce this action and wait for user acknowledgment before proceeding.fprintf/disp strings, because re-running the script with different inputs or a different model will then print stale numbers.help <function> output and on the function's reference page. Use those as the source of truth instead of any inline parameter table in this skill — inline tables go stale across releases and burn context. This skill only flags name-value arguments that materially change the recipe (e.g., ValidationThreshold for accuracy-budgeted pruning). Lookup procedure:help <function> in the live MATLAB session. Fast and reflects the actually-installed release of the toolbox or support package.help returns only a stub like "Run doc <function> for more information." — common for support-package functions whose help redirects to the browser doc — fall back to the agent's web browsing of the online reference page at https://www.mathworks.com/help/<product>/ref/<funcname>.html (lower-case function name). Extract every name-value argument with its default value, formatted as a markdown table, quoting defaults verbatim.which <func> returns "not found") on a system that has the relevant support package installed, the support package is likely on a stale build. Ask the user to update via Add-On Explorer rather than working around the missing function.references/pattern1/compression-decision.md and walk the user through the question flow (hardware + Simulink availability, primary goal, retraining tolerance). Pick the compression and code generation path based on the answers. Compression is not mandatory and the optimal combination of pruning, projection, and quantization depends on the goal — for example, on Cortex-M with a latency-bound LSTM model, the float32 path with CMSIS-DSP outperforms the quantized path because CMSIS-NN provides no INT8 kernel for recurrent layers.references/pattern1/compression-decision.md — hardware target + Simulink availability, primary goal, retraining tolerance. The answers determine the compression techniques and the code-replacement library to use. Even if the hardware target is already stated, you MUST still ask about the primary deployment goal (flash, SRAM, latency, accuracy) and present the user with the recommended recipe for confirmation before executing any compression step.DAGNetwork, SeriesNetwork, or network objectscompression-decision.md[C × T] array with format "CBT" to a sequence model — always reshape to [C × 1 × T] for single-sequence inferencedlnetwork to prepareNetwork — in R2026a the function takes a dlquantizer object (prepareNetwork(quantObj)) and mutates it in place. The legacy net = prepareNetwork(net) form is no longer definedThis skill covers C/C++ code generation for CPU targets (Cortex-M, Cortex-A/R,
x86) via MATLAB Coder and Embedded Coder, and GPU targets (CUDA/TensorRT) via
Pattern 2's DeepLearningConfig options. The following deployment targets use
different toolchains and are NOT covered:
| Target | Toolchain | Notes |
|--------|-----------|-------|
| FPGA / SoC | HDL Coder + Deep Learning HDL Toolbox | Generates HDL (VHDL/Verilog) from dlnetwork |
| PLC | Simulink PLC Coder | Generates Structured Text for PLCs from Simulink models |
If the user's target falls into one of these categories, inform them that this skill
does not cover that workflow and suggest the relevant toolchain.
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders.
Copyright 2026 The MathWorks, Inc.
Take matlab/matlab-deploy-embedded-ai from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.