This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Code Generation

Generate C/C++ code and MEX functions for Statistics and Machine Learning Toolbox™ functions

MATLAB® Coder™ generates readable and portable C and C++ code from Statistics and Machine Learning Toolbox functions that support code generation. For example, you can classify new observations on hardware devices that cannot run MATLAB by deploying a trained support vector machine (SVM) classification model to the device using code generation.

You can generate C/C++ code for the Statistics and Machine Learning Toolbox functions in several ways.

  • Code generation for the object function (predict, random, knnsearch, or rangesearch) of a machine learning model — Use saveCompactModel, loadCompactModel, and codegen. Save a trained model by using saveCompactModel. Define an entry-point function that loads the saved model by using loadCompactModel and calls the object function. Then use codegen to generate code for the entry-point function.

  • Code generation for the predict and update functions of an SVM model — Create a coder configurer by using learnerCoderConfigurer and then generate code by using generateCode. You can update model parameters in the generated C/C++ code without having to regenerate the code.

  • Other functions that support code generation — Use codegen. Define an entry-point function that calls the function that supports code generation. Then generate C/C++ code for the entry-point function by using codegen.

To learn about code generation, see Introduction to Code Generation.

Functions

expand all

saveCompactModelSave model object in file for code generation
loadCompactModelReconstruct model object from saved model for code generation

Create Coder Configurer Object

learnerCoderConfigurerCreate coder configurer of machine learning model

Work with Coder Configurer Object

generateCodeGenerate C/C++ code using coder configurer
generateFilesGenerate MATLAB files for code generation using coder configurer
validatedUpdateInputsValidate and extract machine learning model parameters to update
updateUpdate support vector machine (SVM) model parameters for code generation

Objects

ClassificationSVMCoderConfigurerCoder configurer for support vector machine (SVM) classification model
RegressionSVMCoderConfigurerCoder configurer for support vector machine (SVM) regression model

Topics

Code-Generation-Enabled Functions

Code Generation Support, Usage Notes, and Limitations

View code generation usage notes, limitations, and the list of code-generation-enabled Statistics and Machine Learning Toolbox functions.

Code Generation Workflows

Introduction to Code Generation

Learn how to generate C/C++ code for Statistics and Machine Learning Toolbox functions.

General Code Generation Workflow

Generate code for Statistics and Machine Learning Toolbox functions that do not use machine learning model objects.

Code Generation for Prediction of Machine Learning Model at Command Line

Generate code for the prediction of a classification or regression model at the command line.

Code Generation for Prediction of Machine Learning Model Using MATLAB Coder App

Generate code for the prediction of a classification or regression model by using the MATLAB Coder app.

Code Generation for Prediction and Update Using Coder Configurer

Generate code for the prediction of an SVM model using a coder configurer, and update model parameters in the generated code.

Code Generation and Classification Learner App

Train a classification model using the Classification Learner app, and generate C/C++ code for prediction.

Code Generation for Nearest Neighbor Searcher

Generate code for finding nearest neighbors using a nearest neighbor searcher model.

Specify Variable-Size Arguments for Code Generation

Generate code that accepts input arguments whose size might change at run time.

Code Generation Applications

Predict Class Labels Using MATLAB Function Block

Generate code from a Simulink® model that classifies data using an SVM model.

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 Stateflow

Generate code from a Stateflow® model that classifies data using a discriminant analysis classifier.

Code Generation for Image Classification

Generate code from a MATLAB function that classifies images of digits using a trained classification model.

Human Activity Recognition Simulink Model for Smartphone Deployment

Generate code from a classification Simulink model prepared for deployment to a smartphone.