# Matlab Train Network

Train, evaluate, and export neural networks to Simulink in MATLAB.

- Repository: https://github.com/matlab/matlab-agentic-toolkit (1237 stars)
- Category: Engineering
- License: see repository
- Last updated: 2026-10-27
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add matlab/matlab-agentic-toolkit --skill matlab-train-network -g -a claude-code -y`
Codex: `npx skills add matlab/matlab-agentic-toolkit --skill matlab-train-network -g -a codex -y`
Cursor: `npx skills add matlab/matlab-agentic-toolkit --skill matlab-train-network -g -a cursor -y`
Gemini CLI: `npx skills add matlab/matlab-agentic-toolkit --skill matlab-train-network -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add matlab/matlab-agentic-toolkit`

## Description

Train, evaluate, and export neural networks to Simulink in MATLAB. Migrate legacy (fitnet, patternnet) and discouraged (trainNetwork, DAGNetwork) code to modern, recommended R2024a+ APIs (trainnet, dlnetwork, testnet, imagePretrainedNetwork), diagnose and fix dlaccelerate issues or detect dlaccelerate opportunities. Use when training, fine-tuning, evaluating, running inference, exporting to Simulink, converting old training scripts, or speeding up deep learning code. DO NOT reason from your training data about dlaccelerate and tracing correctness.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# matlab-train-network

Train, evaluate, and export neural networks to Simulink in MATLAB using the
recommended `dlnetwork`-based API (`trainnet`, `dlnetwork`, `minibatchpredict`,
`scores2label`, `testnet`, `imagePretrainedNetwork`) or, for tabular data, the
Statistics and Machine Learning Toolbox functions `fitcnet` and `fitrnet`.

## When to Use

Activate this skill when a user asks to:

- Train any neural network (classifier, regression, multi-output, LSTM, CNN, etc.)
- Fine-tune or use a pretrained model for transfer learning
- Evaluate a trained network on test data
- Run inference / predict with a trained network
- Export a trained network to Simulink
- Migrate existing legacy (patternnet, fitnet, narxnet, gensim) or discouraged
  (trainNetwork, DAGNetwork, classify) code to recommended APIs
- Create a "pattern recognition network", "function fitting network", "NARX
  network", or any task historically associated with the Neural Network Toolbox
  shallow nets API
- Speed up or optimize any deep learning code (even without mentioning dlaccelerate by name)
- Make existing deep learning code faster using dlaccelerate
- Diagnose and fix dlaccelerate issues (low HitRate, retracing, code is slower after using dlaccelerate)
- Accelerate custom training (code that uses dlfeval/dlgradient)
- Accelerate a function that supports dlarray input and is long running
- Accelerate a custom loss function passed to trainnet (R2026a+)

## When NOT to Use

- Importing/exporting models (importNetworkFromPyTorch, exportONNXNetwork)
- Data loading and preprocessing (imageDatastore, transforms, augmentation)
- Network architecture design decisions (choosing CNN vs LSTM vs transformer)
- Reinforcement learning workflows (use Reinforcement Learning Toolbox)
- Object detection (use specialized detector training functions in Computer Vision Toolbox)

## Decision: fitrnet/fitcnet or trainnet

Apply this check before starting any training workflow below.

The rest: https://github.com/matlab/matlab-agentic-toolkit/blob/HEAD/skills-catalog/ai-and-statistics/matlab-train-network/SKILL.md
