Machine Learning in Simulink
Implement machine learning functionality in Simulink® models by using blocks from the Statistics and Machine Learning block library, included in Statistics and Machine Learning Toolbox™. This toolbox provides blocks to perform the following workflows:
Import a trained classification or regression model object into Simulink using a classification predict or regression predict block.
Train a machine learning model in the Classification Learner or Regression Learner app, and export the model to Simulink.
Use incremental learning blocks in Simulink to continuously update and monitor drift in machine learning models in real time.
Find nearest neighbors in the data to query points and perform cluster analysis in Simulink using the KNN Search block.
Coexecute trained Python® machine learning models in Simulink using Python coexecution blocks.
Blocks
Topics
Classification
- Predict Class Labels Using ClassificationSVM Predict Block
This example shows how to use the ClassificationSVM Predict block for label prediction in Simulink®. - Predict Class Labels Using ClassificationTree Predict Block
Train a classification decision tree model using the Classification Learner app, and then use the ClassificationTree Predict block for label prediction. - Predict Class Labels Using ClassificationLinear Predict Block
This example shows how to use the ClassificationLinear Predict block for label prediction in Simulink®. (Since R2023a) - Predict Class Labels Using ClassificationECOC Predict Block
Train an ECOC classification model, and then use the ClassificationECOC Predict block for label prediction. (Since R2023a) - Predict Class Labels Using ClassificationEnsemble Predict Block
Train a classification ensemble model with optimal hyperparameters, and then use the ClassificationEnsemble Predict block for label prediction. - Predict Class Labels Using ClassificationNaiveBayes Predict Block
Train a naive Bayes classification model, and then use the ClassificationNaiveBayes Predict block for label prediction. (Since R2024a) - Predict Class Labels Using ClassificationNeuralNetwork Predict Block
Train a neural network classification model, and then use the ClassificationNeuralNetwork Predict block for label prediction. - Predict Class Labels Using ClassificationKNN Predict Block
Train a nearest neighbor classification model, and then use the ClassificationKNN Predict block for label prediction. - Predict Class Labels Using ClassificationDiscriminant Predict Block
Train a discriminant analysis classification model, and then use the ClassificationDiscriminant Predict block for label prediction. (Since R2023b) - Predict Class Labels Using ClassificationKernel Predict Block
Train a Gaussian kernel classification model, and then use the ClassificationKernel Predict block for label prediction. (Since R2024b)
Regression
- Predict Responses Using RegressionSVM Predict Block
Train a support vector machine (SVM) regression model using the Regression Learner app, and then use the RegressionSVM Predict block for response prediction. - Predict Responses Using RegressionTree Predict Block
This example shows how to use the RegressionTree Predict block for response prediction in Simulink®. - Predict Responses Using RegressionLinear Predict Block
This example shows how to use the RegressionLinear Predict block for response prediction in Simulink®. (Since R2023a) - Predict Responses Using RegressionEnsemble Predict Block
Train a regression ensemble model with optimal hyperparameters, and then use the RegressionEnsemble Predict block for response prediction. - Predict Responses Using RegressionNeuralNetwork Predict Block
Train a neural network regression model, and then use the RegressionNeuralNetwork Predict block for response prediction. - Predict Responses Using RegressionGP Predict Block
Train a Gaussian process (GP) regression model, and then use the RegressionGP Predict block for response prediction. - Predict Responses Using RegressionKernel Predict Block
This example shows how to use the RegressionKernel Predict block for response prediction in Simulink®. (Since R2024b)
Incremental Learning
- Perform Incremental Learning Using IncrementalClassificationLinear Fit and Predict Blocks
Perform incremental learning with the IncrementalClassificationLinear Fit block and predict labels with the IncrementalClassificationLinear Predict block. (Since R2023b) - Perform Incremental Learning Using IncrementalRegressionLinear Fit and Predict Blocks
Perform incremental learning with the IncrementalRegressionLinear Fit block and predict responses with the IncrementalRegressionLinear Predict block. (Since R2023b) - Perform Incremental Learning Using IncrementalClassificationECOC Fit and Predict Blocks
Perform incremental learning with the IncrementalClassificationECOC Fit block and predict labels with the IncrementalClassificationECOC Predict block. (Since R2024a) - Perform Incremental Learning Using IncrementalClassificationKernel Fit and Predict Blocks
Perform incremental learning with the IncrementalClassificationKernel Fit block and predict labels with the IncrementalClassificationKernel Predict block. (Since R2024b) - Perform Incremental Learning Using IncrementalRegressionKernel Fit and Predict Blocks
Perform incremental learning with the IncrementalRegressionKernel Fit block and predict responses with the IncrementalRegressionKernel Predict block. (Since R2024b) - Perform Incremental Learning and Track Performance Metrics Using Update Metrics Block
Perform incremental learning and track performance metrics with the Update Metrics block. (Since R2023b) - Monitor Drift Using Detect Drift Block
This example shows how to use the Detect Drift block for monitoring drift in a data stream in Simulink®. (Since R2024b) - In-Place Model Update of Offline Linear Model Using IncrementalClassificationLinear Predict Block
Perform in-place model update without regenerating deployed code. (Since R2025a)
Incremental Learning Templates
- Configure Simulink Template for Conditionally Enabled Incremental Linear Classification
Configure the Simulink Enabled Execution Incremental Learning template to perform incremental linear classification. (Since R2024a) - Configure Simulink Template for Conditionally Enabled Incremental Linear Regression
Configure the Simulink Enabled Execution Incremental Learning template to perform incremental linear regression. (Since R2024a) - Configure Simulink Template for Rate-Based Incremental Linear Classification
Configure the Simulink Rate-Based Incremental Learning template to perform incremental linear classification. (Since R2024a) - Configure Simulink Template for Rate-Based Incremental Linear Regression
Configure the Simulink Rate-Based Incremental Learning template to perform incremental linear regression. (Since R2024a) - Configure Simulink Template for Drift-Aware Incremental Learning
Configure the Drift-Aware Training for Incremental Learning template to perform drift-aware learning. (Since R2025a)
Cluster Analysis and Anomaly Detection
- Find Nearest Neighbors Using KNN Search Block
Train a nearest neighbor searcher model, and then use the KNN Search block for label prediction. (Since R2023b)
Python Coexecution
- Predict Cluster Assignments Using Python Scikit-learn Model Predict Block
This example shows how to use the Scikit-learn Model Predict block for prediction in Simulink®. - Predict Responses Using Custom Python Model in Simulink
This example shows how to use the Custom Python Model Predict block for prediction in Simulink®.
Export Learner App Models to Simulink
- Export Classification Model to Make Predictions in Simulink
Train a model in Classification Learner, and then export the model to Simulink. - Export Regression Model to Make Predictions in Simulink
Train a model in Regression Learner, and then export the model to Simulink.
Code Generation
- System Objects for Classification and Code Generation
Generate code from a System object™ for making predictions using a trained classification model, and use the System object in a Simulink model. - Predict Class Labels Using MATLAB Function Block
Generate code from a Simulink model that classifies data using an SVM model. - Predict Class Labels Using Stateflow
Generate code from a Stateflow® model that classifies data using a discriminant analysis classifier.
Related Information
- Deep Learning with Simulink (Deep Learning Toolbox)