$npx -y skills add matlab/matlab-agentic-toolkit --skill matlab-deploy-embedded-aiDeploy AI models to embedded hardware using MathWorks tools (MATLAB, Simulink, Embedded Coder). Covers two workflow patterns: (1) MathWorks-native or imported models rebuilt as dlnetwork for lean hardware, (2) direct C/C++ code generation from PyTorch and LiteRT models. Both patt
| 1 | # Embedded AI for Engineered Systems |
| 2 | |
| 3 | Deploy AI models to embedded hardware using MATLAB® and Simulink®. This skill is |
| 4 | written specifically for **MATLAB R2026a** and uses APIs, functions, and workflows |
| 5 | introduced in that release. It covers the complete lifecycle: model creation or |
| 6 | import, verification, compression, system-level simulation, and code generation |
| 7 | for resource-constrained targets. |
| 8 | |
| 9 | Requires MATLAB R2026a or newer. Core toolboxes: Deep Learning Toolbox, Statistics |
| 10 | and Machine Learning Toolbox, MATLAB Coder, Embedded Coder, Simulink, and |
| 11 | Fixed-Point Designer. Workflow-specific support packages are checked during |
| 12 | Environment Discovery. The MATLAB and Simulink Agentic Toolkits must be available |
| 13 | so the agent can drive a live MATLAB and Simulink session through MCP tools. |
| 14 | |
| 15 | ## When to Use |
| 16 | |
| 17 | - Deploying a trained neural network (MATLAB-native or imported) to embedded hardware |
| 18 | - Generating C or CUDA code from a deep learning model for ARM Cortex-M/A/R, x86, or GPU targets |
| 19 | - Importing PyTorch, ONNX, TensorFlow, or LiteRT models into MATLAB for embedded deployment |
| 20 | - Compressing AI models (quantization, pruning, projection) to fit resource-constrained hardware |
| 21 | - Integrating AI inference into a Simulink system model for closed-loop simulation before code generation |
| 22 | - Using `loadPyTorchExportedProgram`, `importNetworkFromPyTorch`, `importNetworkFromONNX`, `importNetworkFromTensorFlow`, `dlquantizer`, `exportNetworkToSimulink`, or Embedded Coder with AI models |
| 23 | - Choosing between MathWorks-native code generation and direct PyTorch/LiteRT code generation |
| 24 | |
| 25 | ## When NOT to Use |
| 26 | |
| 27 | - Training a model purely for research with no deployment target — use Deep Learning Toolbox documentation directly |
| 28 | - Deploying to cloud/server endpoints (no embedded target) — use MATLAB Production Server or MATLAB Compiler SDK |
| 29 | - 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 |
| 30 | - Generating code for non-AI Simulink models — use standard Embedded Coder workflows |
| 31 | - Converting between model formats without an embedded deployment goal (e.g., ONNX to MATLAB for desktop inference only) |
| 32 | |
| 33 | ## Workflow Pattern Selection |
| 34 | |
| 35 | This skill uses two deployment patterns: |
| 36 | |
| 37 | - **Pattern 1 — MATLAB Network Codegen:** Import or build a `dlnetwork`, optionally |
| 38 | compress it, then generate C/C++ via MATLAB Coder or export to Simulink. |
| 39 | See [`references/pattern1/workflow.md`](references/pattern1/workflow.md). |
| 40 | - **Pattern 2 — PyTorch/LiteRT Direct Codegen:** Load a PyTorch (.pt2) or LiteRT |
| 41 | (.tflite) model directly and generate C/C++ without converting to a dlnetwork. |
| 42 | See [`references/pattern2/workflow.md`](references/pattern2/workflow.md). |
| 43 | |
| 44 | ### Decision Tree |
| 45 | |
| 46 | Primary discriminator for external models: **deployment capabilities + hardware class**. |
| 47 | |
| 48 | ``` |
| 49 | Q1: Where does the AI model come from? |
| 50 | | |
| 51 | +-- Trained in MATLAB, or requires training in MATLAB -------> Pattern 1 |
| 52 | | |
| 53 | +-- External framework (PyTorch, TF, ONNX, Keras) --> Q2 |
| 54 | | |
| 55 | Q2: Does the deployment need any of these? |
| 56 | | - Quantization (INT8 via dlquantizer) |
| 57 | | - Pruning or projection |
| 58 | | - Weight inspection / modification |
| 59 | | - exportNetworkToSimulink integration |
| 60 | | |
| 61 | +-- YES --> Pattern 1 (import as dlnetwork) |
| 62 | | |
| 63 | +-- NO ---> Q3 |
| 64 | | |
| 65 | Q3: What is the deployment target? |
| 66 | | |
| 67 | +-- Cortex-M: Pattern 1 |
| 68 | | (compression and Simulink verification typically needed) |
| 69 | | |
| 70 | +-- x86 / GPU: |
| 71 | | +-- PyTorch (.pt2) or LiteRT (.tflite) --> Pattern 2 |
| 72 | | +-- ONNX, TF, Keras --> Pattern 1 (convert to ONNX recommended) |
| 73 | | |
| 74 | +-- Cortex-A/R: |
| 75 | +-- Small model --> Pattern 1 |
| 76 | | (import as dlnetwork, then codegen) |
| 77 | +-- Large model: |
| 78 | +-- PyTorch (.pt2) or LiteRT (.tflite) --> P |