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 (
rangesearch) of a machine learning model — Use
codegen. Save a trained
model by using
an entry-point function that loads the saved model by using
calls the object function. Then use
codegen to generate code
for the entry-point function.
Code generation for the
update functions of a tree model, an SVM model, a linear
model, or a multiclass error-correcting output codes (ECOC)
classification model using SVM or linear binary learners — 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
You can also generate fixed-point C/C++ code for the prediction of an SVM model, a decision tree model, and an ensemble of decision trees. This type of code generation requires Fixed-Point Designer™.
For a list of functions that support code generation, see Function List (C/C++ Code Generation)
To learn about code generation, see Introduction to Code Generation.
|Create coder configurer of machine learning model|
|Coder configurer of binary decision tree model for multiclass classification|
|Coder configurer for support vector machine (SVM) for one-class and binary classification|
|Coder configurer for linear binary classification of high-dimensional data|
|Coder configurer for multiclass model using binary learners|
Learn how to generate C/C++ code for Statistics and Machine Learning Toolbox functions.
Generate code for Statistics and Machine Learning Toolbox functions that do not use machine learning model objects.
Generate code for the prediction of a classification or regression model at the command line.
Generate code for the prediction of a classification or regression model by using the MATLAB Coder app.
Generate code for the prediction of a model using a coder configurer, and update model parameters in the generated code.
Train a classification model using the Classification Learner app, and generate C/C++ code for prediction.
Generate code for finding nearest neighbors using a nearest neighbor searcher model.
Generate code that accepts input arguments whose size might change at run time.
Convert categorical predictors to numeric dummy variables before fitting an SVM classifier and generating code.
Generate fixed-point code for the prediction of an SVM classification or regression model.
Generate code that fits a probability distribution object to sample data and evaluates the fitted distribution object.
Generate code for classifying numeric data in a table using a binary decision tree.
Generate code from a Simulink® model that classifies data using an SVM model.
Generate code from a System object™ for making predictions using a trained classification model, and use the System object in a Simulink model.
Generate code from a Stateflow® model that classifies data using a discriminant analysis classifier.